25 #include <sys/types.h> 37 #include <lib$routines.h> 64 rlTimeEx::rlTimeEx(
int Year,
int Month,
int Day,
int Hour,
int Minute,
int Second,
int Millisecond)
110 double mod = fmod(
seconds*1000, 1000);
195 while(*format !=
'\0')
197 if (strncmp(format,
"dd",2) == 0)
199 sprintf(buf,
"%02d",
day);
204 else if(strncmp(format,
"d",1) == 0)
206 sprintf(buf,
"%d",
day);
211 else if(strncmp(format,
"MMM",3) == 0)
214 if(
month == 1) strcpy(buf,
"Jan");
215 if(
month == 2) strcpy(buf,
"Feb");
216 if(
month == 3) strcpy(buf,
"Mar");
217 if(
month == 4) strcpy(buf,
"Apr");
218 if(
month == 5) strcpy(buf,
"May");
219 if(
month == 6) strcpy(buf,
"Jun");
220 if(
month == 7) strcpy(buf,
"Jul");
221 if(
month == 8) strcpy(buf,
"Aug");
222 if(
month == 9) strcpy(buf,
"Sep");
223 if(
month == 10) strcpy(buf,
"Oct");
224 if(
month == 11) strcpy(buf,
"Nov");
225 if(
month == 12) strcpy(buf,
"Dec");
230 else if(strncmp(format,
"MM",2) == 0)
232 sprintf(buf,
"%02d",
month);
237 else if(strncmp(format,
"M",1) == 0)
239 sprintf(buf,
"%d",
month);
244 else if(strncmp(format,
"yyyy",4) == 0)
246 sprintf(buf,
"%4d",
year);
251 else if(strncmp(format,
"yy",2) == 0)
253 sprintf(buf,
"%4d",
year);
254 strcpy(dest,&buf[2]);
255 dest += strlen(&buf[2]);
258 else if(strncmp(format,
"hh",2) == 0)
260 if (
hour > 12) sprintf(buf,
"%02d",
hour - 12);
261 else if(
hour == 0) sprintf(buf,
"%02d", 12);
262 else sprintf(buf,
"%02d",
hour);
267 else if(strncmp(format,
"h",1) == 0)
269 if (
hour > 12) sprintf(buf,
"%2d",
hour - 12);
270 else if(
hour == 0) sprintf(buf,
"%2d", 12);
271 else sprintf(buf,
"%2d",
hour);
276 else if(strncmp(format,
"HH",2) == 0)
278 sprintf(buf,
"%02d",
hour);
283 else if(strncmp(format,
"H",1) == 0)
285 sprintf(buf,
"%d",
hour);
290 else if(strncmp(format,
"mm",2) == 0)
292 sprintf(buf,
"%02d",
minute);
297 else if(strncmp(format,
"m",1) == 0)
304 else if(strncmp(format,
"ss",2) == 0)
306 sprintf(buf,
"%02d",
second);
311 else if(strncmp(format,
"s",1) == 0)
318 else if(strncmp(format,
"zzz",3) == 0)
325 else if(strncmp(format,
"z",1) == 0)
332 else if(strncmp(format,
"AP",2) == 0)
334 if (
hour == 0) strcpy(dest,
"PM");
335 else if(
hour < 13) strcpy(dest,
"AM");
336 else strcpy(dest,
"PM");
337 dest += strlen(
"AM");
340 else if(strncmp(format,
"ap",2) == 0)
342 if (
hour == 0) strcpy(dest,
"pm");
343 else if(
hour < 13) strcpy(dest,
"am");
344 else strcpy(dest,
"pm");
345 dest += strlen(
"am");
348 else if(strncmp(format,
"A",1) == 0)
350 if (
hour == 0) strcpy(dest,
"PM");
351 else if(
hour < 13) strcpy(dest,
"AM");
352 else strcpy(dest,
"PM");
353 dest += strlen(
"AM");
356 else if(strncmp(format,
"a",1) == 0)
358 if (
hour == 0) strcpy(dest,
"pm");
359 else if(
hour < 13) strcpy(dest,
"am");
360 else strcpy(dest,
"pm");
361 dest += strlen(
"am");
384 gettimeofday(&tv, &tz);
387 tms->tm_year += 1900;
391 second = (
int)tms->tm_sec;
392 minute = (int)tms->tm_min;
393 hour = (
int)tms->tm_hour;
394 day = (int)tms->tm_mday;
395 month = (
int)tms->tm_mon;
396 year = (int)tms->tm_year;
405 hour = (
int)tds.hour;
407 month = (
int)tds.month;
408 year = (int)tds.year;
430 if(lstat(filename,&statbuf))
return -1;
432 if(stat(filename,&statbuf))
return -1;
434 tms = localtime(&statbuf.st_mtime);
437 tms->tm_year += 1900;
441 second = (int)tms->tm_sec;
442 minute = (
int)tms->tm_min;
443 hour = (int)tms->tm_hour;
444 day = (
int)tms->tm_mday;
445 month = (int)tms->tm_mon;
446 year = (
int)tms->tm_year;
458 t.tm_mon =
month - 1;
459 t.tm_year =
year - 1900;
463 tv.tv_sec = mktime(&t);
465 settimeofday(&tv,NULL);
470 struct dsc$descriptor_s d_time;
471 char smonth[12][4],buf[64];
474 memset (smonth , 0,
sizeof(smonth));
475 memcpy (smonth [0],
"JAN", 3);
476 memcpy (smonth [1],
"FEB", 3);
477 memcpy (smonth [2],
"MAR", 3);
478 memcpy (smonth [3],
"APR", 3);
479 memcpy (smonth [4],
"MAY", 3);
480 memcpy (smonth [5],
"JUN", 3);
481 memcpy (smonth [6],
"JUL", 3);
482 memcpy (smonth [7],
"AUG", 3);
483 memcpy (smonth [8],
"SEP", 3);
484 memcpy (smonth [9],
"OCT", 3);
485 memcpy (smonth [10],
"NOV", 3);
486 memcpy (smonth [11],
"DEC", 3);
488 sprintf(buf,
"%02d-%3.3s-%04d %02d:%02d:%02d.%02d",
498 d_time.dsc$w_length = strlen(buf);
499 d_time.dsc$b_dtype = DSC$K_DTYPE_T;
500 d_time.dsc$b_class = DSC$K_CLASS_S;
501 d_time.dsc$a_pointer = buf;
503 sys$bintim(&d_time, &vbt);
567 int special = y % 400;
568 if(hth == 0 && special != 0) maxmonth = 28;
610 if(t.
day > maxmonth) { t.
month++; t.
day -= maxmonth; }
639 if(m <= 0) { m += 12; y--; }
652 int special = y % 400;
653 if(hth == 0 && special != 0) maxmonth = 28;
768 if(
day != time.
day)
return 0;
792 if(diff.
year < 0)
return 1;
793 if(diff.
month < 0)
return 1;
794 if(diff.
day < 0)
return 1;
795 if(diff.
hour < 0)
return 1;
796 if(diff.
minute < 0)
return 1;
797 if(diff.
second < 0)
return 1;
804 if((*
this) == time)
return 1;
805 if((*
this) < time)
return 1;
824 if(diff.
year < 0)
return 1;
825 if(diff.
month < 0)
return 1;
826 if(diff.
day < 0)
return 1;
827 if(diff.
hour < 0)
return 1;
828 if(diff.
minute < 0)
return 1;
829 if(diff.
second < 0)
return 1;
836 if((*
this) == time)
return 1;
837 if((*
this) > time)
return 1;
846 memset(&begin,0,
sizeof(tm));
847 memset(&test,0,
sizeof(tm));
856 test.tm_year =
year - 1900;
857 test.tm_mon =
month - 1;
863 time_t t0 = mktime(&begin);
864 time_t t1 = mktime(&test);
866 return difftime(t1,t0) + (((double)
millisecond) / 1000);
rlTimeEx(int Year=0, int Month=0, int Day=0, int Hour=0, int Minute=0, int Second=0, int Millisecond=0)
const char * getTimeString()
int operator>=(rlTimeEx &time) const
const char * toString(const char *format)
int operator>(rlTimeEx &time) const
void setTimeFromString(const char *time_string)
int operator<(rlTimeEx &time) const
rlTimeEx operator-(rlTimeEx &time) const
int getFileModificationTime(const char *filename)
double secondsSinceEpoche() const
const char * getIsoTimeString()
int operator==(rlTimeEx &time) const
void setTimeFromSeconds(double seconds)
int operator<=(rlTimeEx &time) const
rlTimeEx operator+(rlTimeEx &time) const
rlTimeEx & operator+=(rlTimeEx &time)
rlTimeEx & operator-=(rlTimeEx &time)
void setTimeFromIsoString(const char *iso_time_string)