diff options
| author | Dmitry Antipov | 2015-01-14 12:43:43 +0300 |
|---|---|---|
| committer | Dmitry Antipov | 2015-01-14 12:43:43 +0300 |
| commit | da396beb6e0b9ef9a45afb849eeda26da14038af (patch) | |
| tree | 4e982b2c41c107e7f456a2c09b82db16d0a049a5 /src | |
| parent | d4b352af3e7d5c1afc719fb1f8c7c578642d8250 (diff) | |
| download | emacs-da396beb6e0b9ef9a45afb849eeda26da14038af.tar.gz emacs-da396beb6e0b9ef9a45afb849eeda26da14038af.zip | |
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')
| -rw-r--r-- | src/ChangeLog | 5 | ||||
| -rw-r--r-- | src/editfns.c | 67 |
2 files changed, 36 insertions, 36 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 3523ea41570..4f7ef6ef03e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -16,6 +16,11 @@ | |||
| 16 | * callproc.c (encode_current_directory, call_process): | 16 | * callproc.c (encode_current_directory, call_process): |
| 17 | * process.c (Fstart_process): Use it. | 17 | * process.c (Fstart_process): Use it. |
| 18 | 18 | ||
| 19 | Consistently handle time zone specification. | ||
| 20 | * editfns.c (decode_time_zone): New function, refactored out from ... | ||
| 21 | (Fencode_time): ... adjusted user. | ||
| 22 | (Fset_time_zone_rule): Use decode_time_zone. | ||
| 23 | |||
| 19 | 2015-01-14 Paul Eggert <eggert@cs.ucla.edu> | 24 | 2015-01-14 Paul Eggert <eggert@cs.ucla.edu> |
| 20 | 25 | ||
| 21 | Use bool for boolean in xmenu.c, xml.c | 26 | Use bool for boolean in xmenu.c, xml.c |
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) | |||
| 2063 | return n - offset; | 2063 | return n - offset; |
| 2064 | } | 2064 | } |
| 2065 | 2065 | ||
| 2066 | /* Decode ZONE as a time zone specification. */ | ||
| 2067 | |||
| 2068 | static const char * | ||
| 2069 | decode_time_zone (Lisp_Object zone) | ||
| 2070 | { | ||
| 2071 | const char *tzstring = NULL; | ||
| 2072 | |||
| 2073 | if (EQ (zone, Qt)) | ||
| 2074 | tzstring = "UTC0"; | ||
| 2075 | else if (STRINGP (zone)) | ||
| 2076 | tzstring = SSDATA (zone); | ||
| 2077 | else if (INTEGERP (zone)) | ||
| 2078 | { | ||
| 2079 | static char const tzbuf_format[] = "XXX%s%"pI"d:%02d:%02d"; | ||
| 2080 | char tzbuf[sizeof tzbuf_format + INT_STRLEN_BOUND (EMACS_INT)]; | ||
| 2081 | EMACS_INT abszone = eabs (XINT (zone)), zone_hr = abszone / (60 * 60); | ||
| 2082 | int zone_min = (abszone / 60) % 60, zone_sec = abszone % 60; | ||
| 2083 | |||
| 2084 | sprintf (tzbuf, tzbuf_format, &"-"[XINT (zone) < 0], | ||
| 2085 | zone_hr, zone_min, zone_sec); | ||
| 2086 | tzstring = tzbuf; | ||
| 2087 | } | ||
| 2088 | else | ||
| 2089 | xsignal2 (Qerror, build_string ("Invalid time zone specification"), zone); | ||
| 2090 | return tzstring; | ||
| 2091 | } | ||
| 2092 | |||
| 2066 | DEFUN ("encode-time", Fencode_time, Sencode_time, 6, MANY, 0, | 2093 | DEFUN ("encode-time", Fencode_time, Sencode_time, 6, MANY, 0, |
| 2067 | doc: /* Convert SECOND, MINUTE, HOUR, DAY, MONTH, YEAR and ZONE to internal time. | 2094 | doc: /* Convert SECOND, MINUTE, HOUR, DAY, MONTH, YEAR and ZONE to internal time. |
| 2068 | This is the reverse operation of `decode-time', which see. | 2095 | 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) */) | |||
| 2105 | value = mktime (&tm); | 2132 | value = mktime (&tm); |
| 2106 | else | 2133 | else |
| 2107 | { | 2134 | { |
| 2108 | static char const tzbuf_format[] = "XXX%s%"pI"d:%02d:%02d"; | 2135 | timezone_t tz = tzalloc (decode_time_zone (zone)); |
| 2109 | char tzbuf[sizeof tzbuf_format + INT_STRLEN_BOUND (EMACS_INT)]; | ||
| 2110 | const char *tzstring; | ||
| 2111 | |||
| 2112 | if (EQ (zone, Qt)) | ||
| 2113 | tzstring = "UTC0"; | ||
| 2114 | else if (STRINGP (zone)) | ||
| 2115 | tzstring = SSDATA (zone); | ||
| 2116 | else if (INTEGERP (zone)) | ||
| 2117 | { | ||
| 2118 | EMACS_INT abszone = eabs (XINT (zone)); | ||
| 2119 | EMACS_INT zone_hr = abszone / (60*60); | ||
| 2120 | int zone_min = (abszone/60) % 60; | ||
| 2121 | int zone_sec = abszone % 60; | ||
| 2122 | sprintf (tzbuf, tzbuf_format, &"-"[XINT (zone) < 0], | ||
| 2123 | zone_hr, zone_min, zone_sec); | ||
| 2124 | tzstring = tzbuf; | ||
| 2125 | } | ||
| 2126 | else | ||
| 2127 | tzstring = 0; | ||
| 2128 | |||
| 2129 | timezone_t tz = tzstring ? tzalloc (tzstring) : 0; | ||
| 2130 | if (! tz) | ||
| 2131 | error ("Invalid time zone specification"); | ||
| 2132 | value = mktime_z (tz, &tm); | 2136 | value = mktime_z (tz, &tm); |
| 2133 | tzfree (tz); | 2137 | tzfree (tz); |
| 2134 | } | 2138 | } |
| @@ -2265,7 +2269,8 @@ the data it can't find. */) | |||
| 2265 | DEFUN ("set-time-zone-rule", Fset_time_zone_rule, Sset_time_zone_rule, 1, 1, 0, | 2269 | DEFUN ("set-time-zone-rule", Fset_time_zone_rule, Sset_time_zone_rule, 1, 1, 0, |
| 2266 | doc: /* Set the local time zone using TZ, a string specifying a time zone rule. | 2270 | doc: /* Set the local time zone using TZ, a string specifying a time zone rule. |
| 2267 | If TZ is nil, use implementation-defined default time zone information. | 2271 | If TZ is nil, use implementation-defined default time zone information. |
| 2268 | If TZ is t, use Universal Time. | 2272 | If TZ is t, use Universal Time. If TZ is an integer, it is treated as in |
| 2273 | `encode-time'. | ||
| 2269 | 2274 | ||
| 2270 | Instead of calling this function, you typically want (setenv "TZ" TZ). | 2275 | Instead of calling this function, you typically want (setenv "TZ" TZ). |
| 2271 | That changes both the environment of the Emacs process and the | 2276 | That changes both the environment of the Emacs process and the |
| @@ -2273,17 +2278,7 @@ variable `process-environment', whereas `set-time-zone-rule' affects | |||
| 2273 | only the former. */) | 2278 | only the former. */) |
| 2274 | (Lisp_Object tz) | 2279 | (Lisp_Object tz) |
| 2275 | { | 2280 | { |
| 2276 | const char *tzstring; | 2281 | const char *tzstring = NILP (tz) ? initial_tz : decode_time_zone (tz); |
| 2277 | |||
| 2278 | if (! (NILP (tz) || EQ (tz, Qt))) | ||
| 2279 | CHECK_STRING (tz); | ||
| 2280 | |||
| 2281 | if (NILP (tz)) | ||
| 2282 | tzstring = initial_tz; | ||
| 2283 | else if (EQ (tz, Qt)) | ||
| 2284 | tzstring = "UTC0"; | ||
| 2285 | else | ||
| 2286 | tzstring = SSDATA (tz); | ||
| 2287 | 2282 | ||
| 2288 | block_input (); | 2283 | block_input (); |
| 2289 | set_time_zone_rule (tzstring); | 2284 | set_time_zone_rule (tzstring); |