(Fencode_time, Fset_time_zone_rule): Use UTC if the zone is t.
[bpt/emacs.git] / src / editfns.c
index 164ee9c..88d8841 100644 (file)
@@ -711,7 +711,7 @@ DEFUN ("encode-time", Fencode_time, Sencode_time, 6, MANY, 0,
   "Convert SECOND, MINUTE, HOUR, DAY, MONTH, YEAR and ZONE to internal time.\n\
 This is the reverse operation of `decode-time', which see.\n\
 ZONE defaults to the current time zone rule.  This can\n\
-be a string (as from `set-time-zone-rule'), or it can be a list\n\
+be a string or t (as from `set-time-zone-rule'), or it can be a list\n\
 (as from `current-time-zone') or an integer (as from `decode-time')\n\
 applied without consideration for daylight savings time.\n\
 \n\
@@ -757,7 +757,9 @@ If you want them to stand for years in this century, you must do that yourself."
       char *tzstring;
       char **oldenv = environ, **newenv;
       
-      if (STRINGP (zone))
+      if (zone == Qt)
+       tzstring = "UTC0";
+      else if (STRINGP (zone))
        tzstring = (char *) XSTRING (zone)->data;
       else if (INTEGERP (zone))
        {
@@ -765,6 +767,10 @@ If you want them to stand for years in this century, you must do that yourself."
          sprintf (tzbuf, "XXX%s%d:%02d:%02d", "-" + (XINT (zone) < 0),
                   abszone / (60*60), (abszone/60) % 60, abszone % 60);
          tzstring = tzbuf;
+#ifdef _NEXT_SOURCE
+         /* On NEXTSTEP, timezone environment var is ignored.  */
+         tm.tm_gmtoff = -abszone;
+#endif
        }
       else
        error ("Invalid time zone specification");
@@ -910,7 +916,8 @@ static char **environbuf;
 
 DEFUN ("set-time-zone-rule", Fset_time_zone_rule, Sset_time_zone_rule, 1, 1, 0,
   "Set the local time zone using TZ, a string specifying a time zone rule.\n\
-If TZ is nil, use implementation-defined default time zone information.")
+If TZ is nil, use implementation-defined default time zone information.\n\
+If TZ is t, use Universal Time.")
   (tz)
      Lisp_Object tz;
 {
@@ -918,6 +925,8 @@ If TZ is nil, use implementation-defined default time zone information.")
 
   if (NILP (tz))
     tzstring = 0;
+  else if (tz == Qt)
+    tzstring = "UTC0";
   else
     {
       CHECK_STRING (tz, 0);
@@ -932,6 +941,17 @@ If TZ is nil, use implementation-defined default time zone information.")
   return Qnil;
 }
 
+/* These two values are known to load tz files in buggy implementations.
+   Their values shouldn't matter in non-buggy implementations.
+   We don't use string literals for these strings, 
+   since if a string in the environment is in readonly
+   storage, it runs afoul of bugs in SVR4 and Solaris 2.3.
+   See Sun bugs 1113095 and 1114114, ``Timezone routines
+   improperly modify environment''.  */
+
+static char set_time_zone_rule_tz1[] = "TZ=GMT0";
+static char set_time_zone_rule_tz2[] = "TZ=GMT1";
+
 /* Set the local time zone rule to TZSTRING.
    This allocates memory into `environ', which it is the caller's
    responsibility to free.  */
@@ -982,17 +1002,13 @@ set_time_zone_rule (tzstring)
        not load a tz file, tzset can dump core (see Sun bug#1225179).
        The following code works around these bugs.  */
 
-    /* These two values are known to load tz files in buggy implementations.
-       Their values shouldn't matter in non-buggy implementations.  */
-    char *tz1 = "TZ=GMT0";
-    char *tz2 = "TZ=GMT1";
-
     if (tzstring)
       {
        /* Temporarily set TZ to a value that loads a tz file
           and that differs from tzstring.  */
        char *tz = *newenv;
-       *newenv = strcmp (tzstring, tz1 + 3) == 0 ? tz2 : tz1;
+       *newenv = (strcmp (tzstring, set_time_zone_rule_tz1 + 3) == 0
+                  ? set_time_zone_rule_tz2 : set_time_zone_rule_tz1);
        tzset ();
        *newenv = tz;
       }
@@ -1000,10 +1016,10 @@ set_time_zone_rule (tzstring)
       {
        /* The implied tzstring is unknown, so temporarily set TZ to
           two different values that each load a tz file.  */
-       *to = tz1;
+       *to = set_time_zone_rule_tz1;
        to[1] = 0;
        tzset ();
-       *to = tz2;
+       *to = set_time_zone_rule_tz2;
        tzset ();
        *to = 0;
       }