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.
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);
}
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
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);