diff options
author | Dmitry Antipov <dmantipov@yandex.ru> | 2015-01-14 12:43:43 +0300 |
---|---|---|
committer | Dmitry Antipov <dmantipov@yandex.ru> | 2015-01-14 12:43:43 +0300 |
commit | da396beb6e0b9ef9a45afb849eeda26da14038af (patch) | |
tree | 4e982b2c41c107e7f456a2c09b82db16d0a049a5 /src/editfns.c | |
parent | d4b352af3e7d5c1afc719fb1f8c7c578642d8250 (diff) | |
download | emacs-da396beb6e0b9ef9a45afb849eeda26da14038af.tar.gz |
Consistently handle time zone specification.
* editfns.c (decode_time_zone): New function, refactored out from ...
(Fencode_time): ... adjusted user.
(Fset_time_zone_rule): Use decode_time_zone.
Diffstat (limited to 'src/editfns.c')
-rw-r--r-- | src/editfns.c | 67 |
1 files changed, 31 insertions, 36 deletions
diff --git a/src/editfns.c b/src/editfns.c index cd15f6569aa..e097893a6f9 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -2063,6 +2063,33 @@ check_tm_member (Lisp_Object obj, int offset) return n - offset; } +/* Decode ZONE as a time zone specification. */ + +static const char * +decode_time_zone (Lisp_Object zone) +{ + const char *tzstring = NULL; + + if (EQ (zone, Qt)) + tzstring = "UTC0"; + else if (STRINGP (zone)) + tzstring = SSDATA (zone); + else if (INTEGERP (zone)) + { + static char const tzbuf_format[] = "XXX%s%"pI"d:%02d:%02d"; + char tzbuf[sizeof tzbuf_format + INT_STRLEN_BOUND (EMACS_INT)]; + EMACS_INT abszone = eabs (XINT (zone)), zone_hr = abszone / (60 * 60); + int zone_min = (abszone / 60) % 60, zone_sec = abszone % 60; + + sprintf (tzbuf, tzbuf_format, &"-"[XINT (zone) < 0], + zone_hr, zone_min, zone_sec); + tzstring = tzbuf; + } + else + xsignal2 (Qerror, build_string ("Invalid time zone specification"), zone); + return tzstring; +} + DEFUN ("encode-time", Fencode_time, Sencode_time, 6, MANY, 0, doc: /* Convert SECOND, MINUTE, HOUR, DAY, MONTH, YEAR and ZONE to internal time. This is the reverse operation of `decode-time', which see. @@ -2105,30 +2132,7 @@ usage: (encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE) */) value = mktime (&tm); else { - static char const tzbuf_format[] = "XXX%s%"pI"d:%02d:%02d"; - char tzbuf[sizeof tzbuf_format + INT_STRLEN_BOUND (EMACS_INT)]; - const char *tzstring; - - if (EQ (zone, Qt)) - tzstring = "UTC0"; - else if (STRINGP (zone)) - tzstring = SSDATA (zone); - else if (INTEGERP (zone)) - { - EMACS_INT abszone = eabs (XINT (zone)); - EMACS_INT zone_hr = abszone / (60*60); - int zone_min = (abszone/60) % 60; - int zone_sec = abszone % 60; - sprintf (tzbuf, tzbuf_format, &"-"[XINT (zone) < 0], - zone_hr, zone_min, zone_sec); - tzstring = tzbuf; - } - else - tzstring = 0; - - timezone_t tz = tzstring ? tzalloc (tzstring) : 0; - if (! tz) - error ("Invalid time zone specification"); + timezone_t tz = tzalloc (decode_time_zone (zone)); value = mktime_z (tz, &tm); tzfree (tz); } @@ -2265,7 +2269,8 @@ the data it can't find. */) DEFUN ("set-time-zone-rule", Fset_time_zone_rule, Sset_time_zone_rule, 1, 1, 0, doc: /* Set the local time zone using TZ, a string specifying a time zone rule. If TZ is nil, use implementation-defined default time zone information. -If TZ is t, use Universal Time. +If TZ is t, use Universal Time. If TZ is an integer, it is treated as in +`encode-time'. Instead of calling this function, you typically want (setenv "TZ" TZ). That changes both the environment of the Emacs process and the @@ -2273,17 +2278,7 @@ variable `process-environment', whereas `set-time-zone-rule' affects only the former. */) (Lisp_Object tz) { - const char *tzstring; - - if (! (NILP (tz) || EQ (tz, Qt))) - CHECK_STRING (tz); - - if (NILP (tz)) - tzstring = initial_tz; - else if (EQ (tz, Qt)) - tzstring = "UTC0"; - else - tzstring = SSDATA (tz); + const char *tzstring = NILP (tz) ? initial_tz : decode_time_zone (tz); block_input (); set_time_zone_rule (tzstring); |