]> Savannah Git Hosting - gnulib.git/commitdiff
strftime: %z is -00 if unknown
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 14 Jan 2017 19:35:34 +0000 (11:35 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 14 Jan 2017 19:36:52 +0000 (11:36 -0800)
* lib/strftime.c (DO_TZ_OFFSET): Omit arg 'negative'; it's now
the caller's responsibility to set 'negative_number'.  All uses changed.
(__strftime_internal): Put '-' before a zero UTC offset if the time
zone abbreviation starts with "-", which is the recently-introduced
tzdb convention for an unknown UTC offset that is arbitrarily set to 0.
* tests/test-strftime.c: Test for this.

ChangeLog
lib/strftime.c
tests/test-strftime.c

index e74f075337879e4c24a4b8acb0267f2a4a366415..f13c784edaa8995dcf00025b627f3cf820559e55 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2017-01-14  Paul Eggert  <eggert@cs.ucla.edu>
+
+       strftime: %z is -00 if unknown
+       * lib/strftime.c (DO_TZ_OFFSET): Omit arg 'negative'; it's now
+       the caller's responsibility to set 'negative_number'.  All uses changed.
+       (__strftime_internal): Put '-' before a zero UTC offset if the time
+       zone abbreviation starts with "-", which is the recently-introduced
+       tzdb convention for an unknown UTC offset that is arbitrarily set to 0.
+       * tests/test-strftime.c: Test for this.
+
 2017-01-10  Paul Eggert  <eggert@cs.ucla.edu>
 
        dfa: port to older GCC
index 218faabd59909ff0bb00dde0f841b3fc6d320756..8091f3d08ed45aa7813a8a20ad8296a62d4ebd71 100644 (file)
@@ -739,11 +739,10 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
           /* The mask is not what you might think.
              When the ordinal i'th bit is set, insert a colon
              before the i'th digit of the time zone representation.  */
-#define DO_TZ_OFFSET(d, negative, mask, v) \
+#define DO_TZ_OFFSET(d, mask, v) \
           do                                                                  \
             {                                                                 \
               digits = d;                                                     \
-              negative_number = negative;                                     \
               tz_colon_mask = mask;                                           \
               u_number_value = v;                                             \
               goto do_tz_offset;                                              \
@@ -1444,6 +1443,7 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
               }
 #endif
 
+            negative_number = diff < 0 || (diff == 0 && *zone == '-');
             hour_diff = diff / 60 / 60;
             min_diff = diff / 60 % 60;
             sec_diff = diff % 60;
@@ -1451,13 +1451,13 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
             switch (colons)
               {
               case 0: /* +hhmm */
-                DO_TZ_OFFSET (5, diff < 0, 0, hour_diff * 100 + min_diff);
+                DO_TZ_OFFSET (5, 0, hour_diff * 100 + min_diff);
 
               case 1: tz_hh_mm: /* +hh:mm */
-                DO_TZ_OFFSET (6, diff < 0, 04, hour_diff * 100 + min_diff);
+                DO_TZ_OFFSET (6, 04, hour_diff * 100 + min_diff);
 
               case 2: tz_hh_mm_ss: /* +hh:mm:ss */
-                DO_TZ_OFFSET (9, diff < 0, 024,
+                DO_TZ_OFFSET (9, 024,
                               hour_diff * 10000 + min_diff * 100 + sec_diff);
 
               case 3: /* +hh if possible, else +hh:mm, else +hh:mm:ss */
@@ -1465,7 +1465,7 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
                   goto tz_hh_mm_ss;
                 if (min_diff != 0)
                   goto tz_hh_mm;
-                DO_TZ_OFFSET (3, diff < 0, 0, hour_diff);
+                DO_TZ_OFFSET (3, 0, hour_diff);
 
               default:
                 goto bad_format;
index c7df5f07d0b53362a663f29f938a35f74be082ab..102e1680515694950c47f839ab0aa3b9c8c5f85c 100644 (file)
@@ -96,6 +96,8 @@ static struct tzalloc_test TZ[] =
     { 0, "JST-9"                       },
 #define NZ 5
     { 0, "NZST-12NZDT,M9.5.0,M4.1.0/3" },
+#define Unknown 6
+    { 0, "<-00>0" },
     { 0 }
   };
 
@@ -121,18 +123,21 @@ static struct localtime_rz_test LT[] =
     { TZ+CentEur,          0, "1970-01-01 01:00:00 +0100 (CET)",  0 },
     { TZ+Japan  ,          0, "1970-01-01 09:00:00 +0900 (JST)",  0 },
     { TZ+NZ     ,          0, "1970-01-01 13:00:00 +1300 (NZDT)", 1 },
+    { TZ+Unknown,          0, "1970-01-01 00:00:00 -0000 (-00)",  0 },
     { TZ+Pacific,  500000001, "1985-11-04 16:53:21 -0800 (PST)",  0 },
     { TZ+Arizona,  500000001, "1985-11-04 17:53:21 -0700 (MST)",  0 },
     { TZ+UTC    ,  500000001, "1985-11-05 00:53:21 +0000 (UTC)",  0 },
     { TZ+CentEur,  500000001, "1985-11-05 01:53:21 +0100 (CET)",  1 },
     { TZ+Japan  ,  500000001, "1985-11-05 09:53:21 +0900 (JST)",  0 },
     { TZ+NZ     ,  500000001, "1985-11-05 13:53:21 +1300 (NZDT)", 0 },
+    { TZ+Unknown,  500000001, "1985-11-05 00:53:21 -0000 (-00)",  0 },
     { TZ+Pacific, 1000000002, "2001-09-08 18:46:42 -0700 (PDT)",  0 },
     { TZ+Arizona, 1000000002, "2001-09-08 18:46:42 -0700 (MST)",  0 },
     { TZ+UTC    , 1000000002, "2001-09-09 01:46:42 +0000 (UTC)",  0 },
     { TZ+CentEur, 1000000002, "2001-09-09 03:46:42 +0200 (CEST)", 0 },
     { TZ+Japan  , 1000000002, "2001-09-09 10:46:42 +0900 (JST)",  0 },
     { TZ+NZ     , 1000000002, "2001-09-09 13:46:42 +1200 (NZST)", 0 },
+    { TZ+Unknown, 1000000002, "2001-09-09 01:46:42 -0000 (-00)",  0 },
     { 0 }
   };