diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-01-20 23:40:39 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-01-20 23:40:39 -0800 |
commit | b9b4014c02f36f5b468283ed6ef64783146306cf (patch) | |
tree | 3b5054d4a63e9014981c079ef52f2bb776b41885 /lib.c | |
parent | da6ce99db9ac21b417262f5d23e605aee391b70e (diff) | |
download | txr-b9b4014c02f36f5b468283ed6ef64783146306cf.tar.gz txr-b9b4014c02f36f5b468283ed6ef64783146306cf.tar.bz2 txr-b9b4014c02f36f5b468283ed6ef64783146306cf.zip |
* lib.c (broken_down_time_list): New static function.
(time_fields_local, time_fields_utc): New functions.
* lib.h (time_fields_local, time_fields_utc): Declared.
* eval.c (eval_init): Intern time_fields_local and time_fields_utc
as intrinsic functions.
* txr.1: Documented.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -5163,6 +5163,40 @@ val time_string_utc(val time, val format) return timestr; } +static val broken_time_list(struct tm *tms) +{ + return list(num(tms->tm_year + 1900), + num_fast(tms->tm_mon + 1), + num_fast(tms->tm_mday), + num_fast(tms->tm_hour), + num_fast(tms->tm_min), + num_fast(tms->tm_sec), + tms->tm_isdst ? t : nil, + nao); +} + +val time_fields_local(val time) +{ + struct tm tms; + time_t secs = c_num(time); + + if (localtime_r(&secs, &tms) == 0) + return nil; + + return broken_time_list(&tms); +} + +val time_fields_utc(val time) +{ + struct tm tms; + time_t secs = c_num(time); + + if (gmtime_r(&secs, &tms) == 0) + return nil; + + return broken_time_list(&tms); +} + static val make_time_impl(time_t (*pmktime)(struct tm *), val year, val month, val day, val hour, val minute, val second, |