home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xntp3.zip / include / ntp_calendar.h < prev    next >
C/C++ Source or Header  |  1989-07-30  |  2KB  |  73 lines

  1. /*
  2.  * ntp_calendar.h - definitions for the calendar time-of-day routine
  3.  */
  4. struct calendar {
  5.     u_short year;    /* year (A.D.) */
  6.     u_short yearday;    /* day of year, 1 = January 1 */
  7.     u_char month;    /* month, 1 = January */
  8.     u_char monthday;    /* day of month */
  9.     u_char hour;    /* hour of day, midnight = 0 */
  10.     u_char minute;    /* minute of hour */
  11.     u_char second;    /* second of minute */
  12. };
  13.  
  14. /*
  15.  * Days in each month.  30 days hath September...
  16.  */
  17. #define    JAN    31
  18. #define    FEB    28
  19. #define    FEBLEAP    29
  20. #define    MAR    31
  21. #define    APR    30
  22. #define    MAY    31
  23. #define    JUN    30
  24. #define    JUL    31
  25. #define    AUG    31
  26. #define    SEP    30
  27. #define    OCT    31
  28. #define    NOV    30
  29. #define    DEC    31
  30.  
  31. /*
  32.  * We deal in a 4 year cycle starting at March 1, 1900.  We assume
  33.  * we will only want to deal with dates since then, and not to exceed
  34.  * the rollover day in 2036.
  35.  */
  36. #define    SECSPERMIN    (60)            /* seconds per minute */
  37. #define    MINSPERHR    (60)            /* minutes per hour */
  38. #define    HRSPERDAY    (24)            /* hours per day */
  39. #define    DAYSPERYEAR    (365)            /* days per year */
  40.  
  41. #define    SECSPERDAY    (SECSPERMIN*MINSPERHR*HRSPERDAY)
  42. #define SECSPERYEAR    (365 * SECSPERDAY)    /* regular year */
  43. #define    SECSPERLEAPYEAR    (366 * SECSPERDAY)    /* leap year */
  44.  
  45. #define    MAR1900        ((JAN+FEB) * SECSPERDAY) /* no leap year in 1900 */
  46. #define    DAYSPERCYCLE    (365+365+365+366)    /* 3 normal years plus leap */
  47. #define    SECSPERCYCLE    (DAYSPERCYCLE*SECSPERDAY)
  48. #define    YEARSPERCYCLE    4
  49.  
  50. /*
  51.  * Gross hacks.  I have illicit knowlege that there won't be overflows
  52.  * here, the compiler often can't tell this.
  53.  */
  54. #define    TIMES60(val)    (((val)<<6) - ((val)<<2))    /* *64 - *4 */
  55. #define    TIMES24(val)    (((val)<<4) + ((val)<<3))    /* *16 + *8 */
  56. #define    TIMESDPERC(val)    (((val)<<10) + ((val)<<8) \
  57.             + ((val)<<7) + ((val)<<5) \
  58.             + ((val)<<4) + ((val)<<2) + (val))    /* *big* hack */
  59.  
  60. /*
  61.  * Another big hack.  Cycle 22 started on March 1, 1988.  This is
  62.  * STARTCYCLE22 seconds after the start of cycle 0.
  63.  */
  64. #define    CYCLE22        (22)
  65. #define    STARTCYCLE22    2777068800
  66. #define    MAR1988        (STARTCYCLE22 + MAR1900)
  67.  
  68. /*
  69.  * The length of January + February in leap and non-leap years.
  70.  */
  71. #define    JANFEBNOLEAP    ((JAN+FEB) * SECSPERDAY)
  72. #define    JANFEBLEAP    ((JAN+FEBLEAP) * SECSPERDAY)
  73.