bool TestExtDatetime::test_gmstrftime() { f_setlocale(2, k_LC_TIME, "en_US.utf8"); int d = f_mktime(20, 0, 0, 12, 31, 98); VS(f_strftime("%b %d %Y %H:%M:%S", d), "Dec 31 1998 20:00:00"); VS(f_gmstrftime("%b %d %Y %H:%M:%S", d), "Jan 01 1999 04:00:00"); int t = f_mktime(0,0,0, 6, 27, 2006); VS(f_strftime("%a %A %b %B %c %C %d %D %e %g %G %h %H %I %j %m %M %n %p " "%r %R %S %t %T %u %U %V %W %w %x %X %y %Y %Z %z %%", t), "Tue Tuesday Jun June Tue 27 Jun 2006 12:00:00 AM PDT 20 27 " "06/27/06 27 06 2006 Jun 00 12 178 06 00 \n AM 12:00:00 AM " "00:00 00 \t 00:00:00 2 26 26 26 2 06/27/2006 12:00:00 AM " "06 2006 PDT -0700 %"); return Count(true); }
bool TestExtDatetime::test_strptime() { String format = "%d/%m/%Y %H:%M:%S"; String strf = f_strftime(format, f_strtotime("10/03/2004 15:54:19")); VS(strf, "03/10/2004 15:54:19"); VS(f_print_r(f_strptime(strf, format), true), "Array\n" "(\n" " [tm_sec] => 19\n" " [tm_min] => 54\n" " [tm_hour] => 15\n" " [tm_mday] => 3\n" " [tm_mon] => 9\n" " [tm_year] => 104\n" " [tm_wday] => 0\n" " [tm_yday] => 276\n" " [unparsed] => \n" ")\n"); return Count(true); }
bool TestExtDatetime::test_mktime() { int lastday = f_mktime(0, 0, 0, 3, 0, 2000); VS(f_strftime("Last day in Feb 2000 is: %d", lastday), "Last day in Feb 2000 is: 29"); /** * We are not supporting negative parameters * lastday = f_mktime(0, 0, 0, 4, -31, 2000); * VS(f_strftime("Last day in Feb 2000 is: %d", lastday), * "Last day in Feb 2000 is: 29"); */ VS(f_date("M-d-Y", f_mktime(0, 0, 0, 12, 32, 1997)), "Jan-01-1998"); VS(f_date("M-d-Y", f_mktime(0, 0, 0, 13, 1, 1997)), "Jan-01-1998"); VS(f_date("M-d-Y", f_mktime(0, 0, 0, 1, 1, 1998)), "Jan-01-1998"); VS(f_date("M-d-Y", f_mktime(0, 0, 0, 1, 1, 98)), "Jan-01-1998"); VS(f_mktime(), time(NULL)); VS(f_date("h", f_mktime(9)), "09"); return Count(true); }
/* Get current system time in seconds since 2000 * The type of the value popped from the stack * determines what is returned. * If integer, the result is also an integer. * If real (complex), the result is also real, * with microsecond precision (if available). * If string, it is assumed to be a format string, * and it is passed to strftime to get a formatted time string. */ void f_time(union argument *arg) { struct value val, val2; double time_now; #ifdef HAVE_SYS_TIME_H struct timeval tp; gettimeofday(&tp, NULL); tp.tv_sec -= SEC_OFFS_SYS; time_now = tp.tv_sec + (tp.tv_usec/1000000.0); #else time_now = (double) time(NULL); time_now -= SEC_OFFS_SYS; #endif (void) arg; /* Avoid compiler warnings */ pop(&val); switch(val.type) { case INTGR: push(Ginteger(&val, (int) time_now)); break; case CMPLX: push(Gcomplex(&val, time_now, 0.0)); break; case STRING: push(&val); /* format string */ push(Gcomplex(&val2, time_now, 0.0)); f_strftime(arg); break; default: int_error(NO_CARET,"internal error: invalid argument type"); } }
bool TestExtDatetime::test_strftime() { int ts = f_mktime(0, 0, 0, 8, 5, 1998); f_setlocale(2, k_LC_TIME, "C"); VS(f_strftime("%A", ts), "Wednesday"); if (f_setlocale(2, k_LC_TIME, "fi_FI")) { VS(f_strftime(" in Finnish is %A,", ts), " in Finnish is keskiviikko,"); } else { SKIP("setlocale() failed"); } if (f_setlocale(2, k_LC_TIME, "fr_FR")) { VS(f_strftime(" in French %A and", ts), " in French mercredi and"); } else { SKIP("setlocale() failed"); } if (f_setlocale(2, k_LC_TIME, "de_DE")) { VS(f_strftime(" in German %A.", ts), " in German Mittwoch."); } else { SKIP("setlocale() failed"); } f_setlocale(2, k_LC_TIME, "C"); /* December 2002 / January 2003 ISOWk M Tu W Thu F Sa Su ----- ---------------------------- 51 16 17 18 19 20 21 22 52 23 24 25 26 27 28 29 1 30 31 1 2 3 4 5 2 6 7 8 9 10 11 12 3 13 14 15 16 17 18 19 */ VS(f_strftime("%V,%G,%Y", f_strtotime("12/28/2002")), "52,2002,2002"); VS(f_strftime("%V,%G,%Y", f_strtotime("12/30/2002")), "01,2003,2002"); VS(f_strftime("%V,%G,%Y", f_strtotime("1/3/2003")), "01,2003,2003"); VS(f_strftime("%V,%G,%Y", f_strtotime("1/10/2003")), "02,2003,2003"); /* December 2004 / January 2005 ISOWk M Tu W Thu F Sa Su ----- ---------------------------- 51 13 14 15 16 17 18 19 52 20 21 22 23 24 25 26 53 27 28 29 30 31 1 2 1 3 4 5 6 7 8 9 2 10 11 12 13 14 15 16 */ VS(f_strftime("%V,%G,%Y", f_strtotime("12/23/2004")), "52,2004,2004"); VS(f_strftime("%V,%G,%Y", f_strtotime("12/31/2004")), "53,2004,2004"); VS(f_strftime("%V,%G,%Y", f_strtotime("1/2/2005")), "53,2004,2005"); VS(f_strftime("%V,%G,%Y", f_strtotime("1/3/2005")), "01,2005,2005"); return Count(true); }