1 /* $MirOS: src/kern/include/mirtime.h,v 1.2 2011/11/20 23:40:11 tg Exp $ */ 2 3 /* Do not include this header, include <time.h> and/or <sys/time.h> */ 4 5 #ifndef SYSKERN_MIRTIME_H 6 #define SYSKERN_MIRTIME_H 1 7 8 9 /* Definition of basic types */ 10 11 12 /* pulled out from <time.h> and/or <sys/time.h> */ 13 14 /* seconds since the epoch */ 15 #ifdef _BSD_TIME_T_ 16 typedef _BSD_TIME_T_ time_t; 17 #undef _BSD_TIME_T_ 18 #endif 19 20 /* calendaric broken-down date */ 21 struct tm { 22 int tm_sec; /* seconds [0-60] */ 23 int tm_min; /* minutes [0-59] */ 24 int tm_hour; /* hours [0-23] */ 25 int tm_mday; /* day of month [1-31] */ 26 int tm_mon; /* month of year - 1 [0-11] */ 27 time_t tm_year; /* year - 1900 */ 28 int tm_wday; /* day of week (0 = sunday) */ 29 int tm_yday; /* day of year [0-365] */ 30 int tm_isdst; /* summer time effective? [0/1] */ 31 long tm_gmtoff; /* offset from UTC in seconds */ 32 char *tm_zone; /* abbreviation of timezone name */ 33 }; 34 35 /* new types */ 36 37 /* Modified Julian Date */ 38 typedef struct { 39 time_t mjd; 40 int32_t sec; 41 } mirtime_mjd; 42 43 44 /* functions */ 45 __BEGIN_DECLS 46 47 /* conversion between time-since-the-epoch with and without leap seconds */ 48 time_t timet2posix(time_t); 49 time_t posix2timet(time_t); 50 51 /* conversion between time-since-the-epoch with leap seconds and MJD */ 52 mirtime_mjd *timet2mjd(mirtime_mjd *, time_t); 53 time_t mjd2timet(mirtime_mjd *); 54 55 /* easy conversion between epoch and calendaric time */ 56 struct tm *timet2tm(struct tm *, time_t); 57 time_t tm2timet(struct tm *); 58 #ifdef __GNUC__ 59 #define timet2tm(dst, src) __extension__({ \ 60 mirtime_mjd timet2tm_storage; \ 61 mjd_explode((dst), timet2mjd(&timet2tm_storage, (src))); \ 62 }) 63 #define tm2timet(src) __extension__({ \ 64 mirtime_mjd tm2timet_storage; \ 65 mjd2timet(mjd_implode(&tm2timet_storage, (src))); \ 66 }) 67 #endif 68 69 /* internal conversion between broken-down calendaric date and MJD */ 70 struct tm *mjd_explode(struct tm *, const mirtime_mjd *); 71 mirtime_mjd *mjd_implode(mirtime_mjd *, const struct tm *); 72 73 /* internal leap second management */ 74 const time_t *mirtime_getleaps(void); 75 int mirtime_isleap(time_t); 76 77 __END_DECLS 78 79 #endif 80