37static char *DAYS[]={
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat"};
39static char *FULLDAYS[]={
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
42static char *MONTHS[]={
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
43 "Aug",
"Sep",
"Oct",
"Nov",
"Dec"};
45static char *FULLMONTHS[]={
"January",
"February",
"March",
"April",
"May",
"June",
46 "July",
"August",
"September",
"October",
"November",
"December"};
49#define IS_LEAP(y) ((y) % 4) == 0 && (! ((y) % 100) == 0 || ((y) % 400) == 0)
50#define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400)
59static sint32 Get_Day(
int month,
int day,
int year)
63 static int DaysAtMonth[] =
64 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
69 days = (year * 365) + (year / 4) - (year / 100) + (year / 400) +
70 DaysAtMonth[month-1] + day;
110 while (days < 0 || days >= (
IS_LEAP (y) ? 366 : 365))
113 long int yg = y + days / 365 - (days % 365 < 0);
116 days -= ((yg - y) * 365
132 static char dayTable[2][13] = {
133 {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
134 {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
137 return(dayTable[isleap][month]);
189 dayoffset=Get_Day(1,1,1970);
190 printf("DAYOFFSET = %d\n",dayoffset);
193 wtime.getTime(month, mday, year, hour, minute, second);
194 printf("\n%s %d %d %d:%02d:%02d\n\n",
195 MONTHS[month-1],mday,year,hour,minute,second);
197 struct timeval unixtime;
198 struct timezone unixtzone;
202 memset(&tmtime,0,sizeof(tmtime));
207 //gettimeofday(&unixtime,&unixtzone);
209 tmtime=*gmtime(&ttime);
211 printf("TIME->CTIME = %s\n",ctime(&ttime));
212 printf("GTOD->CTIE = %s\n",ctime(&(unixtime.tv_sec)));
213 printf("TIME->GMT->ASCTIME = %s\n",asctime(&tmtime));
215***************************************************************/
257 day_+=(seconds/86400);
258 msec_+=(seconds % 86400)*1000;
290 struct _timeb wintime;
293 msec_+=wintime.millitm;
296 struct timeval unixtime;
297 struct timezone unixtzone;
298 gettimeofday(&unixtime,&unixtzone);
300 msec_+=(unixtime.tv_usec/1000);
322 if (*ptr==
'"') ptr++;
331 if (lastWasH==1) lastWasH=2;
332 sprintf(out+strlen(out),
"%c",*ptr);
335 else if (strncmp(ptr,
"\"",1)==0)
339 else if (strncmp(ptr,
":",1)==0)
341 if (lastWasH==1) lastWasH=2;
342 sprintf(out+strlen(out),
":");
345 else if (strncmp(ptr,
"/",1)==0)
347 sprintf(out+strlen(out),
"/");
350 else if (strncmp(ptr,
"c",1)==0)
352 sprintf(out+strlen(out),
"%ld/%ld/%02ld %ld:%02ld:%02ld",
getMonth(),
356 else if (strncmp(ptr,
"dddddd",6)==0)
358 sprintf(out+strlen(out),
"%s %02ld, %ld",FULLMONTHS[
getMonth()-1],
362 else if (strncmp(ptr,
"ddddd",5)==0)
378 else if (strncmp(ptr,
"dd",2)==0)
380 sprintf(out+strlen(out),
"%02ld",
getMDay());
383 else if (strncmp(ptr,
"d",1)==0)
385 sprintf(out+strlen(out),
"%ld",
getMDay());
398 else if (strncmp(ptr,
"mmmm",4)==0)
400 sprintf(out+strlen(out),
"%s",FULLMONTHS[
getMonth()-1]);
403 else if (strncmp(ptr,
"mmm",3)==0)
405 sprintf(out+strlen(out),
"%s",MONTHS[
getMonth()-1]);
408 else if (strncmp(ptr,
"mm",2)==0)
411 sprintf(out+strlen(out),
"%02ld",
getMinute());
413 sprintf(out+strlen(out),
"%02ld",
getMonth());
416 else if (strncmp(ptr,
"m",1)==0)
419 sprintf(out+strlen(out),
"%ld",
getMinute());
421 sprintf(out+strlen(out),
"%ld",
getMonth());
424 else if (strncmp(ptr,
"q",1)==0)
426 sprintf(out+strlen(out),
"%ld",((
getMonth()-1)/4)+1);
429 else if (strncmp(ptr,
"yyyy",4)==0)
431 sprintf(out+strlen(out),
"%ld",
getYear());
434 else if (strncmp(ptr,
"yy",2)==0)
436 sprintf(out+strlen(out),
"%02ld",
getYear()%100);
444 else if (strncmp(ptr,
"hh",2)==0)
446 sprintf(out+strlen(out),
"%02ld",
getHour());
450 else if (strncmp(ptr,
"h",1)==0)
452 sprintf(out+strlen(out),
"%ld",
getHour());
456 else if (strncmp(ptr,
"nn",2)==0)
458 sprintf(out+strlen(out),
"%02ld",
getMinute());
461 else if (strncmp(ptr,
"n",1)==0)
463 sprintf(out+strlen(out),
"%ld",
getMinute());
466 else if (strncmp(ptr,
"ss",2)==0)
468 sprintf(out+strlen(out),
"%02ld",
getSecond());
471 else if (strncmp(ptr,
"s",1)==0)
473 sprintf(out+strlen(out),
"%ld",
getSecond());
476 else if (strncmp(ptr,
"ttttt",5)==0)
482 else if (strncmp(ptr,
"aa",2)==0)
485 sprintf(out+strlen(out),
"%02ld", tmp);
500 sprintf(out+strlen(out),
"%s", ampm);
664 if ((
day_ < 719528) || (
day_ >= 719528+24855))
670 seconds+=(
msec_/1000);
673 tv.tv_usec=(
msec_%1000)*1000;
682 day_=Get_Day(month,mday,year);
683 msec_=(hour*1000*60*60)+(minute*1000*60)+(second*1000);
693 if (Get_Date_From_Day(
day_,year,dayofyear)==
FALSE)
708 if (Get_Date_From_Day(
day_,year,dayofyear)==
FALSE)
711 static int DaysAtMonth[2][12] = {
712 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
713 {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}
721 if (DaysAtMonth[isleap][i] >= dayofyear)
727 mday=dayofyear-DaysAtMonth[isleap][month-1];
730 hour=(
msec_/3600000)%24;
731 minute=(
msec_/60000)%60;
732 second=(
msec_/ 1000)%60;
743 int month,mday,year,hour,minute,second;
744 getTime(month, mday, year, hour, minute, second);
749 int month,mday,year,hour,minute,second;
750 getTime(month, mday, year, hour, minute, second);
755 int month,mday,year,hour,minute,second;
756 getTime(month, mday, year, hour, minute, second);
761 int month,mday,year,hour,minute,second;
762 getTime(month, mday, year, hour, minute, second);
768 int month,mday,year,hour,minute,second;
769 getTime(month, mday, year, hour, minute, second);
776 int month,mday,year,hour,minute,second;
777 getTime(month, mday, year, hour, minute, second);
788 msec_-=(second*1000);
799 msec_-=(minute*60000);
809 hour=(
msec_/3600000)%24;
810 msec_-=(hour*3600000);
811 msec_+=(hour*3600000);
822 int month,mday,year,hour,
min,sec;
827 day_=Get_Day(month,mday,year);
837 int month,mday,year,hour,
min,sec;
842 day_=Get_Day(month,mday,year);
853 int month,mday,year,hour,
min,sec;
858 day_=Get_Day(month,mday,year);
925 if ((retval==-1)||(retval==0))
934 if ((retval==1)||(retval==0))
Xtime operator+(Xtime &other)
bit8 setSecond(sint32 sec)
Xtime & operator-=(const Xtime &other)
bit8 operator==(const Xtime &other) const
Xtime & operator=(const Xtime &other)
bit8 operator>(const Xtime &other) const
bit8 operator<(const Xtime &other) const
bit8 getTimeval(struct timeval &tv)
int compare(const Xtime &other) const
bit8 setHour(sint32 hour)
sint32 getDay(void) const
void addSeconds(sint32 seconds)
int getMinute(void) const
Xtime & operator+=(const Xtime &other)
void set(sint32 newday, sint32 newmsec)
bit8 setYear(sint32 year)
bit8 FormatTime(char *out, char *format)
sint32 getMsec(void) const
bit8 getTime(int &month, int &mday, int &year, int &hour, int &minute, int &second) const
int getSecond(void) const
void setMsec(sint32 msec)
bit8 setTime(int month, int mday, int year, int hour, int minute, int second)
bit8 setMinute(sint32 min)
bit8 operator<=(const Xtime &other) const
Xtime operator-(Xtime &other)
bit8 setMonth(sint32 month)
bit8 operator!=(const Xtime &other) const
bit8 setMDay(sint32 mday)
bit8 operator>=(const Xtime &other) const
#define LEAPS_THRU_END_OF(y)
int Max_Day(int month, int year)