Skip to main content
briefly explain your changes (corrected spelling, fixed grammar, improved formatting)
Source Link
chux
  • 33.7k
  • 2
  • 38
  • 92
  1. Good that OP is using 4 simplifications: year 2000-2099, no DST, no leap second, no timezone. So OP knows of code limitations concerning these. Various elements of this function break without those givens.

  2. Make static unsigned short days a const.

  3. Use a long for your epoch as in:

     void epoch_to_date_time(date_time_t* date_time,unsigned intlong epoch)
    

as unsigned is only guaranteed to range form 0 to at least 65535 which is insufficient here.

  1. For various functions, consider adding const. There are pros and cons to this, but may be beneficial in your case:

     // unsigned int date_time_to_epoch(date_time_t* date_time)
     unsigned int date_time_to_epoch(const date_time_t* date_time)
    
  2. There exist equation based (non-loop) solutions to the year-day that do not need a table like your unsigned short days[4][12]. Code then looks more complicated, but is faster. Please advise if interested.

  3. Most of the magic numbers like 60, 24 are so well-known that constant or macro substitution seems superfluous. But (365*4+1) may benefit with something like "DaysPer4Years".

  1. Good that OP is using 4 simplifications: year 2000-2099, no DST, no leap second, no timezone. So OP knows of code limitations concerning these. Various elements of this function break without those givens.

  2. Make static unsigned short days a const.

  3. Use a long for your epoch in

     void epoch_to_date_time(date_time_t* date_time,unsigned int epoch)
    

as unsigned is only guaranteed to range form 0 to at least 65535 which is insufficient here.

  1. For various functions, consider adding const. There are pros and cons to this, but may be beneficial in your case:

     // unsigned int date_time_to_epoch(date_time_t* date_time)
     unsigned int date_time_to_epoch(const date_time_t* date_time)
    
  2. There exist equation based (non-loop) solutions to the year-day that do not need a table like your unsigned short days[4][12]. Code then looks more complicated, but is faster. Please advise if interested.

  3. Most of the magic numbers like 60, 24 are so well-known that constant or macro substitution seems superfluous. But (365*4+1) may benefit with something like "DaysPer4Years".

  1. Good that OP is using 4 simplifications: year 2000-2099, no DST, no leap second, no timezone. So OP knows of code limitations concerning these. Various elements of this function break without those givens.

  2. Make static unsigned short days a const.

  3. Use a long for your epoch as in:

     void epoch_to_date_time(date_time_t* date_time,unsigned long epoch)
    

as unsigned is only guaranteed to range form 0 to at least 65535 which is insufficient here.

  1. For various functions, consider adding const. There are pros and cons to this, but may be beneficial in your case:

     // unsigned int date_time_to_epoch(date_time_t* date_time)
     unsigned int date_time_to_epoch(const date_time_t* date_time)
    
  2. There exist equation based (non-loop) solutions to the year-day that do not need a table like your unsigned short days[4][12]. Code then looks more complicated, but is faster. Please advise if interested.

  3. Most of the magic numbers like 60, 24 are so well-known that constant or macro substitution seems superfluous. But (365*4+1) may benefit with something like "DaysPer4Years".

added 17 characters in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237
  1. Good that OP is using 4 simplifications: year 2000-2099, no DST, no leap second, no timezone. So OP knows of code limitations concerning these. Various elements of this function break without those givens.

  2. Make static unsigned short days a const.

  3. Use a long for your epoch in void epoch_to_date_time(date_time_t* date_time,unsigned int epoch) as unsigned is only guaranteed to range form 0 to at least 65535 which is insufficient here.

  4. For various functions consider adding const. The is pros and cons to this, but may be beneficial in your case,:

     // unsigned intvoid date_time_to_epochepoch_to_date_time(date_time_t* date_time)
     ,unsigned int date_time_to_epoch(const date_time_t* date_timeepoch)
    
  5. There exist equation based (non-loop) solutions to the year-day that do not need a table like your unsigned short days[4][12]. Code then looks more complicated, but it faster. Please advise if interested.

  6. Most of the magic numbers like 60, 24 are so well known that constant or macro substitution seems superfluous. But (365*4+1) may benefit with something like "DaysPer4Years".

as unsigned is only guaranteed to range form 0 to at least 65535 which is insufficient here.

  1. For various functions, consider adding const. There are pros and cons to this, but may be beneficial in your case:

     // unsigned int date_time_to_epoch(date_time_t* date_time)
     unsigned int date_time_to_epoch(const date_time_t* date_time)
    
  2. There exist equation based (non-loop) solutions to the year-day that do not need a table like your unsigned short days[4][12]. Code then looks more complicated, but is faster. Please advise if interested.

  3. Most of the magic numbers like 60, 24 are so well-known that constant or macro substitution seems superfluous. But (365*4+1) may benefit with something like "DaysPer4Years".

  1. Good that OP is using 4 simplifications: year 2000-2099, no DST, no leap second, no timezone. So OP knows of code limitations concerning these. Various elements of this function break without those givens.

  2. Make static unsigned short days a const.

  3. Use a long for your epoch in void epoch_to_date_time(date_time_t* date_time,unsigned int epoch) as unsigned is only guaranteed to range form 0 to at least 65535 which is insufficient here.

  4. For various functions consider adding const. The is pros and cons to this, but may be beneficial in your case,:

     // unsigned int date_time_to_epoch(date_time_t* date_time)
     unsigned int date_time_to_epoch(const date_time_t* date_time)
    
  5. There exist equation based (non-loop) solutions to the year-day that do not need a table like your unsigned short days[4][12]. Code then looks more complicated, but it faster. Please advise if interested.

  6. Most of the magic numbers like 60, 24 are so well known that constant or macro substitution seems superfluous. But (365*4+1) may benefit with something like "DaysPer4Years".

  1. Good that OP is using 4 simplifications: year 2000-2099, no DST, no leap second, no timezone. So OP knows of code limitations concerning these. Various elements of this function break without those givens.

  2. Make static unsigned short days a const.

  3. Use a long for your epoch in

     void epoch_to_date_time(date_time_t* date_time,unsigned int epoch)
    

as unsigned is only guaranteed to range form 0 to at least 65535 which is insufficient here.

  1. For various functions, consider adding const. There are pros and cons to this, but may be beneficial in your case:

     // unsigned int date_time_to_epoch(date_time_t* date_time)
     unsigned int date_time_to_epoch(const date_time_t* date_time)
    
  2. There exist equation based (non-loop) solutions to the year-day that do not need a table like your unsigned short days[4][12]. Code then looks more complicated, but is faster. Please advise if interested.

  3. Most of the magic numbers like 60, 24 are so well-known that constant or macro substitution seems superfluous. But (365*4+1) may benefit with something like "DaysPer4Years".

added 14 characters in body
Source Link
chux
  • 33.7k
  • 2
  • 38
  • 92
  1. Good that OP is using 4 simplifications: year 2000-2099, no DST, no leap second, no timezone. So OP knows of code limitations concerning these. Various elements of this function break without those givens.

  2. Make static unsigned short days a const.

  3. Use a long for your epoch in void epoch_to_date_time(date_time_t* date_time,unsigned int epoch) as unsigned is only guaranteed to range form 0 to at least 65535 which is insufficient here.

  4. For various functions consider adding const. The is pros and cons to this, but may be beneficial in your case,:

     // unsigned int date_time_to_epoch(date_time_t* date_time)
     unsigned int date_time_to_epoch(const date_time_t* date_time)
    
  5. There exist algorithmicequation based (non-loop) solutions to the year-day that do not need a table like your unsigned short days[4][12]. Code then looks more complicated, but it faster. Please advise if interested.

  6. Most of the magic numbers like 60, 24 are so well known that constant or macro substitution seems superfluous. But (365*4+1) may benefit with something like "DaysPer4Years".

  1. Good that OP is using 4 simplifications: year 2000-2099, no DST, no leap second, no timezone. So OP knows of code limitations concerning these. Various elements of this function break without those givens.

  2. Make static unsigned short days a const.

  3. Use a long for your epoch in void epoch_to_date_time(date_time_t* date_time,unsigned int epoch) as unsigned is only guaranteed to range form 0 to at least 65535 which is insufficient here.

  4. For various functions consider adding const. The is pros and cons to this, but may be beneficial in your case,:

     // unsigned int date_time_to_epoch(date_time_t* date_time)
     unsigned int date_time_to_epoch(const date_time_t* date_time)
    
  5. There exist algorithmic solutions to the year-day that do not need a table like your unsigned short days[4][12]. Code then looks more complicated, but it faster. Please advise if interested.

  6. Most of the magic numbers like 60, 24 are so well known that constant or macro substitution seems superfluous. But (365*4+1) may benefit with something like "DaysPer4Years".

  1. Good that OP is using 4 simplifications: year 2000-2099, no DST, no leap second, no timezone. So OP knows of code limitations concerning these. Various elements of this function break without those givens.

  2. Make static unsigned short days a const.

  3. Use a long for your epoch in void epoch_to_date_time(date_time_t* date_time,unsigned int epoch) as unsigned is only guaranteed to range form 0 to at least 65535 which is insufficient here.

  4. For various functions consider adding const. The is pros and cons to this, but may be beneficial in your case,:

     // unsigned int date_time_to_epoch(date_time_t* date_time)
     unsigned int date_time_to_epoch(const date_time_t* date_time)
    
  5. There exist equation based (non-loop) solutions to the year-day that do not need a table like your unsigned short days[4][12]. Code then looks more complicated, but it faster. Please advise if interested.

  6. Most of the magic numbers like 60, 24 are so well known that constant or macro substitution seems superfluous. But (365*4+1) may benefit with something like "DaysPer4Years".

Source Link
chux
  • 33.7k
  • 2
  • 38
  • 92
Loading