Remove time.string and time.fromstring builtins
They are of dubious value, and the C implementation uses #if.
This commit is contained in:
parent
36e2057616
commit
e19fe0b8bd
22
c/builtins.c
22
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 },
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue