42 #include "uves_time.h"
43 #include "uves_globals.h"
50 #define GET_CENTURY(d) (int) ( (d) / 1000000L)
52 #define GET_CCYEAR(d) (int) ( (d) / 10000L)
54 #define GET_YEAR(d) (int) (((d) % 1000000L) / 10000L)
56 #define GET_MONTH(d) (int) (((d) % 10000L) / 100)
58 #define GET_DAY(d) (int) ( (d) % 100)
61 #define GET_HOUR(t) (int) ( (t) / 1000000L)
63 #define GET_MINUTE(t) (int) (((t) % 1000000L) / 10000L)
65 #define GET_SECOND(t) (int) (((t) % 10000L) / 100)
67 #define GET_CENTI(t) (int) ( (t) % 100)
70 #define MAKE_DATE(c,y,m,d) (long) (c) * 1000000L + \
71 (long) (y) * 10000L + \
72 (long) (m) * 100 + (d)
74 #define MAKE_TIME(h,m,s,c) (long) (h) * 1000000L + \
75 (long) (m) * 10000L + \
76 (long) (s) * 100 + (c)
79 #define INTERVAL_CENTI 1
80 #define INTERVAL_SEC 100
81 #define INTERVAL_MIN 6000
82 #define INTERVAL_HOUR 360000L
83 #define INTERVAL_DAY 8640000L
89 static long timer_to_date(time_t time_secs) ;
90 static long timer_to_time(time_t time_secs) ;
91 static long uves_time_now(
void) ;
92 static long uves_date_now (
void) ;
120 static char date_iso8601[MAX_NAME_SIZE] ;
124 curdate = uves_date_now() ;
125 curtime = uves_time_now() ;
127 snprintf(date_iso8601, MAX_NAME_SIZE-1,
128 "%04d-%02d-%02dT%02d:%02d:%02d",
134 GET_SECOND(curtime));
135 return date_iso8601 ;
153 static long uves_date_now (
void)
155 return (timer_to_date (time (NULL)));
169 static long uves_time_now(
void)
171 struct timeval time_struct;
173 gettimeofday (&time_struct, 0);
174 return (timer_to_time (time_struct.tv_sec)
175 + time_struct.tv_usec / 10000);
191 static long timer_to_date(time_t time_secs)
193 struct tm *time_struct;
195 if (time_secs == 0) {
199 time_struct = localtime (&time_secs);
201 time_struct-> tm_year += 1900;
202 return (MAKE_DATE ( time_struct-> tm_year / 100,
203 time_struct-> tm_year % 100,
204 time_struct-> tm_mon + 1,
205 time_struct-> tm_mday));
225 static long timer_to_time(time_t time_secs)
227 struct tm *time_struct;
229 if (time_secs == 0) {
233 time_struct = localtime (&time_secs);
235 return (MAKE_TIME (time_struct-> tm_hour,
236 time_struct-> tm_min,
237 time_struct-> tm_sec,