diff options
-rw-r--r-- | time.c | 30 | ||||
-rw-r--r-- | txr.1 | 22 |
2 files changed, 49 insertions, 3 deletions
@@ -408,9 +408,15 @@ static val time_meth(val utc_p, val time_struct) val min = slot(time_struct, min_s); val sec = slot(time_struct, sec_s); val dst = slot(time_struct, dst_s); + val gmtoff = slot(time_struct, gmtoff_s); - return (utc_p ? make_time_utc : make_time)(year, month, day, - hour, min, sec, dst); + val out = (utc_p ? make_time_utc : make_time)(year, month, day, + hour, min, sec, dst); + + if (gmtoff) + out = plus(out, gmtoff); + + return out; } static val time_string_meth(val time_struct, val format) @@ -462,9 +468,17 @@ static val time_parse_meth(val time_struct, val format, val string) val time_parse_local(val format, val string) { struct tm tms = epoch_tm(); + if (!strptime_wrap(string, format, &tms)) return nil; +#if HAVE_TM_GMTOFF + { + long gmtoff = tms.TM_GMTOFF; + return num(mktime(&tms) + gmtoff); + } +#else return num(mktime(&tms)); +#endif } val time_parse_utc(val format, val string) @@ -472,7 +486,17 @@ val time_parse_utc(val format, val string) struct tm tms = epoch_tm(); if (!strptime_wrap(string, format, &tms)) return nil; -#if HAVE_TIMEGM +#if HAVE_TIMEGM && HAVE_TM_GMTOFF + { + long gmtoff = tms.TM_GMTOFF; + return num_time(timegm(&tms) + gmtoff); + } +#elif HAVE_TM_GMTOFF + { + long gmtoff = tms.TM_GMTOFF; + return num_time(timegm_hack(&tms) + tms.gmtoff); + } +#elif HAVE_TIMEGM return num_time(timegm(&tms)); #else return num_time(timegm_hack(&tms)); @@ -66896,6 +66896,22 @@ Note: the availability of these three functions depends on the availability of .codn strptime . +Note: on some platforms, like the GNU C Library, the +.code strptime +function supports the parsing of numeric and symbolic time zones. The +.code gmtoff +slot of the structure ends up being set accordingly. +The +.code time-local +and +.code time-utc +functions take the +.code gmtoff +field into account, adjusting the returned time accordingly. + + +If these are specified. + .coNP Methods @ time-local and @ time-utc .synb .mets << time-struct .(time-local) @@ -66931,6 +66947,12 @@ which are applied to or .codn make-time-utc . +Note: if the +.code gmtoff +slot is not +.codn nil , +its value is added to the returned result. + .coNP Method @ time-string .synb .mets << time-struct .(time-string << format ) |