38 #define TU_EXIT_FAILURE 1 39 #define TU_CHECKERROR( EXPR , SUB, STR )\ 40 if ( EXPR ) { fprintf(stderr, "ERROR (%s):\n %s\n", SUB, STR );\ 41 exit(TU_EXIT_FAILURE); } 50 ={0,31,28,31,30,31,30,31,31,30,31,30,31};
52 ={0,31,29,31,30,31,30,31,31,30,31,30,31};
56 = {-1L, -1L, -1L, -1L, 24L, 60L, 60L, 1000L, 1000L};
81 static char string[35];
83 sprintf(
string,
"%3d %2.2d/%2.2d/%4.4d %2.2d:%2.2d:%2.2d.%3.3d%3.3d",
84 td.doy, td.day, td.month, td.year,
85 td.hour, td.min, td.sec, td.msec, td.usec);
98 if (td->year<70) td->
year=td->year+2000;
99 if (td->year<100) td->year=td->year+1900;
123 TU_CHECKERROR((i>13),
"timeutil_doy",
"month value out of range")
140 int res1, res2, res3;
142 if (year<70) { year = year + 2000; }
143 if (year<100) { year = year + 1900; }
145 res1=(int)(year-(
int)(year/4)*4);
146 res2=(int)(year-(
int)(year/100)*100);
147 res3=(int)(year-(
int)(year/400)*400);
149 if (((res1==0) && (res2!=0)) || (res3==0))
174 while(td->day>days[td->month]) {
175 td->day=td->day-days[td->month];
176 td->month=td->month+1;
177 TU_CHECKERROR((td->month>13),
"timeutil_date",
"doy value out of range")
201 if (ptr[i]<0) carry=carry-1;
203 ptr[i-1]=ptr[i-1]+carry;
207 td->doy=td->doy+carry;
210 if (td->year<70) td->year=td->year+2000;
211 if (td->year<100) td->year=td->year+1900;
215 while (td->doy>diy) {
243 sum->sec =td1.
sec +td2.
sec;
244 sum->min =td1.
min +td2.
min;
246 sum->doy =td1.
doy +td2.
doy;
264 if (time1.year >time2.
year)
return 1;
265 if (time1.year <time2.
year)
return -1;
266 if (time1.month >time2.
month)
return 1;
267 if (time1.month <time2.
month)
return -1;
268 if (time1.day >time2.
day)
return 1;
269 if (time1.day <time2.
day)
return -1;
270 if (time1.hour >time2.
hour)
return 1;
271 if (time1.hour <time2.
hour)
return -1;
272 if (time1.min >time2.
min)
return 1;
273 if (time1.min <time2.
min)
return -1;
274 if (time1.sec >time2.
sec)
return 1;
275 if (time1.sec <time2.
sec)
return -1;
276 if (time1.msec >time2.
msec)
return 1;
277 if (time1.msec <time2.
msec)
return -1;
278 if (time1.usec >time2.
usec)
return 1;
279 if (time1.usec <time2.
usec)
return -1;
static int timeutil_DaysInLeapYear[13]
static long int timeutil_limits[TIMEUTIL_N_ELEMENTS]
void timeutil_date(timeutil_Ttime *td, long int doy)
#define TU_CHECKERROR(EXPR, SUB, STR)
#define TIMEUTIL_N_ELEMENTS
int timeutil_is_leap(long int year)
void timeutil_norm(timeutil_Ttime *td)
char * timeutil_print(timeutil_Ttime td)
#define TIMEUTIL_FIRST_LINEAR
void timeutil_finish(timeutil_Ttime *td)
int timeutil_compare(timeutil_Ttime time1, timeutil_Ttime time2)
static int timeutil_DaysInYear[13]
long int timeutil_doy(timeutil_Ttime td)
void timeutil_clear(timeutil_Ttime *td)
void timeutil_add(timeutil_Ttime *sum, timeutil_Ttime td1, timeutil_Ttime td2)