diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-10-12 07:15:15 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-10-12 07:15:15 -0700 |
commit | 4cfe73161d6e00b583c452ef2502862c80d9ce9f (patch) | |
tree | 05fd3d17f74334baead11d439b5183e89997122c | |
parent | 548116bed68b51f86d520eb4ef8825c824a50a5c (diff) | |
download | txr-4cfe73161d6e00b583c452ef2502862c80d9ce9f.tar.gz txr-4cfe73161d6e00b583c452ef2502862c80d9ce9f.tar.bz2 txr-4cfe73161d6e00b583c452ef2502862c80d9ce9f.zip |
Support gmtoff and zone in time struct.
* lib.c (gmtoff_s, zone_s): New symbol variables.
(tm_to_time_struct): Copy tm_gmtoff and tm_zone into
Lisp struct from struct tm, if the platform has these.
(time_fields_to_tm): Zero/null-out the tm_gmtoff
and tm_zone fields of the target structure, if the
platform has them.
(time_init): Intern the gmtoff and zone symbols,
initializing the gmtoff_s and zone_s variables.
Add the gmtoff and zone slots to the time struct.
* txr.1: Documented new slots.
-rw-r--r-- | lib.c | 20 | ||||
-rw-r--r-- | txr.1 | 36 |
2 files changed, 52 insertions, 4 deletions
@@ -117,7 +117,7 @@ val list_f, less_f, greater_f; val prog_string; val time_s, time_local_s, time_utc_s, time_string_s, time_parse_s; -val year_s, month_s, day_s, hour_s, min_s, sec_s, dst_s; +val year_s, month_s, day_s, hour_s, min_s, sec_s, dst_s, gmtoff_s, zone_s; static val env_list; static val recycled_conses; @@ -9397,6 +9397,12 @@ static void tm_to_time_struct(val time_struct, struct tm *ptm) slotset(time_struct, min_s, num_fast(ptm->tm_min)); slotset(time_struct, sec_s, num_fast(ptm->tm_sec)); slotset(time_struct, dst_s, tnil(ptm->tm_isdst)); +#if HAVE_TM_GMTOFF + slotset(time_struct, gmtoff_s, num_fast(ptm->TM_GMTOFF)); +#endif +#if HAVE_TM_ZONE + slotset(time_struct, zone_s, if2(ptm->TM_ZONE, string_utf8(ptm->TM_ZONE))); +#endif } static val broken_time_struct(struct tm *tms) @@ -9471,6 +9477,13 @@ static void time_fields_to_tm(struct tm *ptm, ptm->tm_isdst = -1; else ptm->tm_isdst = 1; + +#if HAVE_TM_GMTOFF + ptm->TM_GMTOFF = 0; +#endif +#if HAVE_TM_ZONE + ptm->TM_ZONE = 0; +#endif } static void time_struct_to_tm(struct tm *ptm, val time_struct, val strict) @@ -9667,12 +9680,15 @@ static void time_init(void) min_s = intern(lit("min"), user_package); sec_s = intern(lit("sec"), user_package); dst_s = intern(lit("dst"), user_package); + gmtoff_s = intern(lit("gmtoff"), user_package); + zone_s = intern(lit("zone"), user_package); time_st = make_struct_type(time_s, nil, list(time_local_s, time_utc_s, time_string_s, time_parse_s, nao), list(year_s, month_s, day_s, - hour_s, min_s, sec_s, dst_s, nao), + hour_s, min_s, sec_s, dst_s, + gmtoff_s, zone_s, nao), nil, nil, nil, nil); static_slot_set(time_st, time_local_s, func_f1(nil, time_meth)); @@ -38352,7 +38352,8 @@ function. .coNP Structure @ time .synb (defstruct time nil - year month day hour min sec dst) + year month day hour min sec dst + gmtoff zone) .syne .desc The @@ -38377,7 +38378,7 @@ January, whereas the C member .code tm_mon uses a zero-based month. The .code dst -slot is a \*(TL Boolean value. The remaining slots +slot is a \*(TL Boolean value. The slots .codn hour , .codn min , and @@ -38388,6 +38389,37 @@ correspond directly to and .codn tm_sec . +The slot +.code gmtoff +represents the number of seconds east of UTC, and +.code zone +holds a string giving the abbreviated time zone name. +On platform where the C type +.code "struct tm" +has fields corresponding to these slots, values for +these slots are calculated and stored into them by the +.code time-struct-local +and +.code time-struct-utc +functions, and also the related +.code time-local +and +.code time-utc +methods. On platform where the corresponding fields are not +present in the C language +.codn "struct tm" , +these slots are unaffected by those functions, +retaining the default initial value +.code nil +or a previously stored value, if applicable. +Lastly, the values of +.code gmtoff +and +.code zone +are not ignored by functions which accept a +.code time +structure as a source of input values. + .coNP Functions @ time-struct-local and @ time-struct-utc .synb .mets (time-struct-local << time ) |