00001
00009 #ifndef _TIMESTAMP_H
00010 #define _TIMESTAMP_H
00011
00012 #include "platform.h"
00013 #include <time.h>
00014
00015 #define NORMALRES
00016
00017 #ifdef VERYHIGHRES
00018 #define TS_SCALE (-9)
00019 #define TS_SECOND ((int64)1000000000)
00020 #define TS_RESOLUTION (1e-9)
00021 #elif defined HIGHRES
00022 #define TS_SCALE (-6)
00023 #define TS_SECOND ((int64)1000000)
00024 #define TS_RESOLUTION (1e-6)
00025 #elif defined MEDIUMRES
00026 #define TS_SCALE (-3)
00027 #define TS_SECOND ((int64)1000)
00028 #define TS_RESOLUTION (1e-3)
00029 #else
00030 #define TS_SCALE (0)
00031 #define TS_SECOND ((int64)1)
00032 #define TS_RESOLUTION (1)
00033 #endif
00034
00035 typedef int64 TIMESTAMP;
00036
00037 #define TS_ZERO ((int64)0)
00038 #define TS_MAX (32482080000LL)
00039 #define TS_INVALID ((int64)-1)
00040 #define TS_NEVER ((int64)(((unsigned int64)-1)>>1))
00041 #define MINYEAR 1970
00042 #define MAXYEAR 2969
00043 #define ISLEAPYEAR(Y) ((Y)%4==0 && ((Y)%100!=0 || (Y)%400==0))
00044
00045 typedef struct s_datetime {
00046 unsigned short year;
00047 unsigned short month;
00048 unsigned short day;
00049 unsigned short hour;
00050 unsigned short minute;
00051 unsigned short second;
00052 unsigned int microsecond;
00053 unsigned short is_dst;
00054 char tz[5];
00055 unsigned short weekday;
00056 unsigned short yearday;
00057 TIMESTAMP timestamp;
00058 } DATETIME;
00060 #ifdef __cplusplus
00061 extern "C" {
00062 #endif
00063
00064
00065 char *timestamp_current_timezone(void);
00066 TIMESTAMP mkdatetime(DATETIME *dt);
00067 int strdatetime(DATETIME *t, char *buffer, int size);
00068 int convert_from_timestamp(TIMESTAMP t, char *buffer, int size);
00069 double timestamp_to_days(TIMESTAMP t);
00070 double timestamp_to_hours(TIMESTAMP t);
00071 double timestamp_to_minutes(TIMESTAMP t);
00072 double timestamp_to_seconds(TIMESTAMP t);
00073 TIMESTAMP convert_to_timestamp(char *value);
00074 int local_datetime(TIMESTAMP ts, DATETIME *dt);
00075
00076 int timestamp_test(void);
00077
00078 char *timestamp_set_tz(char *tzname);
00079 TIMESTAMP timestamp_from_local(time_t t);
00080 time_t timestamp_to_local(TIMESTAMP t);
00081
00082 int local_tzoffset(TIMESTAMP t);
00083
00084 #ifdef __cplusplus
00085 }
00086 #endif
00087
00088 #endif
00089