From e19fe0b8bdd708df3a277ad46ad2ac79f6eba3cc Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Fri, 9 Aug 2019 21:50:52 +0300 Subject: [PATCH] Remove time.string and time.fromstring builtins They are of dubious value, and the C implementation uses #if. --- c/builtins.c | 22 ---------------------- c/timefuncs.c | 32 -------------------------------- c/timefuncs.h | 1 - scheme-tests/unittest.scm | 4 ---- 4 files changed, 59 deletions(-) diff --git a/c/builtins.c b/c/builtins.c index 045a2e9..e36d35d 100644 --- a/c/builtins.c +++ b/c/builtins.c @@ -328,26 +328,6 @@ static double todouble(value_t a, char *fname) type_error(fname, "number", a); } -static value_t fl_time_string(value_t *args, uint32_t nargs) -{ - argcount("time.string", nargs, 1); - double t = todouble(args[0], "time.string"); - char buf[64]; - timestring(t, buf, sizeof(buf)); - return string_from_cstr(buf); -} - -static value_t fl_time_fromstring(value_t *args, uint32_t nargs) -{ - argcount("time.fromstring", nargs, 1); - char *ptr = tostring(args[0], "time.fromstring"); - double t = parsetime(ptr); - int64_t it = (int64_t)t; - if ((double)it == t && fits_fixnum(it)) - return fixnum(it); - return mk_double(t); -} - static value_t fl_path_cwd(value_t *args, uint32_t nargs) { if (nargs > 1) @@ -502,8 +482,6 @@ static struct builtinspec builtin_info[] = { { "vector.alloc", fl_vector_alloc }, { "time.now", fl_time_now }, - { "time.string", fl_time_string }, - { "time.fromstring", fl_time_fromstring }, { "rand", fl_rand }, { "rand.uint32", fl_rand32 }, diff --git a/c/timefuncs.c b/c/timefuncs.c index b3c204a..a555ec3 100644 --- a/c/timefuncs.c +++ b/c/timefuncs.c @@ -78,38 +78,6 @@ double clock_now() #endif } -void timestring(double seconds, char *buffer, size_t len) -{ - time_t tme = (time_t)seconds; - -#if defined(LINUX) || defined(MACOSX) || defined(OPENBSD) || defined(FREEBSD) - char *fmt = "%c"; /* needed to suppress GCC warning */ - struct tm tm; - - localtime_r(&tme, &tm); - strftime(buffer, len, fmt, &tm); -#else - static char *wdaystr[] = { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" - }; - static char *monthstr[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; - struct tm *tm; - int hr; - - tm = localtime(&tme); - hr = tm->tm_hour; - if (hr > 12) - hr -= 12; - if (hr == 0) - hr = 12; - snprintf(buffer, len, "%s %02d %s %d %02d:%02d:%02d %s %s", - wdaystr[tm->tm_wday], tm->tm_mday, monthstr[tm->tm_mon], - tm->tm_year + 1900, hr, tm->tm_min, tm->tm_sec, - tm->tm_hour > 11 ? "PM" : "AM", ""); -#endif -} - #if defined(LINUX) || defined(MACOSX) || defined(OPENBSD) || defined(FREEBSD) extern char *strptime(const char *s, const char *format, struct tm *tm); double parsetime(const char *str) diff --git a/c/timefuncs.h b/c/timefuncs.h index f33568b..c4b8a48 100644 --- a/c/timefuncs.h +++ b/c/timefuncs.h @@ -1,6 +1,5 @@ uint64_t i64time(); double clock_now(); -void timestring(double seconds, char *buffer, size_t len); double parsetime(const char *str); void sleep_ms(int ms); void timeparts(int32_t *buf, double t); diff --git a/scheme-tests/unittest.scm b/scheme-tests/unittest.scm index 00b5430..2891e20 100644 --- a/scheme-tests/unittest.scm +++ b/scheme-tests/unittest.scm @@ -287,10 +287,6 @@ (assert (not (equal? (hash (iota 41)) (hash (iota 42))))) -(if (top-level-bound? 'time.fromstring) - (assert (let ((ts (time.string (time.now)))) - (eqv? ts (time.string (time.fromstring ts)))))) - (assert (equal? 0.0 (+ 0.0 0))) ; tests that + no longer does inexact->exact (assert (equal? 1.0 (* 1.0 1))) ; tests that * no longer does inexact->exact