00001 00008 #ifndef _TIMESTAMP_H 00009 #define _TIMESTAMP_H 00010 00011 #include "platform.h" 00012 #include <time.h> 00013 00014 #define NORMALRES /* use this to control default timestamp resolution */ 00015 00016 #ifdef VERYHIGHRES 00017 #define TS_SCALE (-9) /* system timescale is 1 nanosecond (1e-9 s)*/ 00018 #define TS_SECOND ((int64)1000000000) /* duration of one second */ 00019 #define TS_RESOLUTION (1e-9) /* must match scale */ 00020 #elif defined HIGHRES 00021 #define TS_SCALE (-6) /* system timescale is 1 nanosecond (1e-9 s)*/ 00022 #define TS_SECOND ((int64)1000000) /* duration of one second */ 00023 #define TS_RESOLUTION (1e-6) /* must match scale */ 00024 #elif defined MEDIUMRES 00025 #define TS_SCALE (-3) /* system timescale is 1 nanosecond (1e-9 s)*/ 00026 #define TS_SECOND ((int64)1000) /* duration of one second */ 00027 #define TS_RESOLUTION (1e-3) /* must match scale */ 00028 #else /* NORMALRES */ 00029 #define TS_SCALE (0) /* system timescale is 1 second (1e-0 s)*/ 00030 #define TS_SECOND ((int64)1) /* duration of one second */ 00031 #define TS_RESOLUTION (1) /* must be 10^TS_SCALE */ 00032 #endif 00033 00034 typedef int64 TIMESTAMP; 00035 00036 #define TS_ZERO ((int64)0) 00037 #define TS_MAX (32482080000LL) /* roughly 3000 CE, any date beyond this should be interpreted as TS_NEVER */ 00038 #define TS_INVALID ((int64)-1) 00039 #define TS_NEVER ((int64)(((unsigned int64)-1)>>1)) 00040 #define MINYEAR 1970 00041 #define MAXYEAR 2969 00042 00043 typedef struct s_datetime { 00044 unsigned short year; 00045 unsigned short month; 00046 unsigned short day; 00047 unsigned short hour; 00048 unsigned short minute; 00049 unsigned short second; 00050 unsigned int microsecond; 00051 unsigned short is_dst; 00052 char tz[5]; 00053 unsigned short weekday; 00054 unsigned short yearday; 00055 TIMESTAMP timestamp; 00056 } DATETIME; 00058 /* basic date and time functions */ 00059 char *timestamp_current_timezone(void); 00060 TIMESTAMP mkdatetime(DATETIME *dt); 00061 int strdatetime(DATETIME *t, char *buffer, int size); 00062 int convert_from_timestamp(TIMESTAMP t, char *buffer, int size); 00063 double timestamp_to_days(TIMESTAMP t); 00064 double timestamp_to_hours(TIMESTAMP t); 00065 double timestamp_to_minutes(TIMESTAMP t); 00066 double timestamp_to_seconds(TIMESTAMP t); 00067 TIMESTAMP convert_to_timestamp(char *value); 00068 int local_datetime(TIMESTAMP ts, DATETIME *dt); 00069 00070 int timestamp_test(void); 00071 00072 char *timestamp_set_tz(char *tzname); 00073 TIMESTAMP timestamp_from_local(time_t t); 00074 time_t timestamp_to_local(TIMESTAMP t); 00075 00076 #endif 00077