Discussion:
[PATCH] strftime: %z is -00 if unknown
(too old to reply)
Paul Eggert
2017-01-14 19:39:09 UTC
Permalink
Raw Message
* 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 | 10 ++++++++++
lib/strftime.c | 12 ++++++------
tests/test-strftime.c | 5 +++++
3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e74f075..f13c784 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2017-01-14 Paul 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 <***@cs.ucla.edu>

dfa: port to older GCC
diff --git a/lib/strftime.c b/lib/strftime.c
index 218faab..8091f3d 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -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;
diff --git a/tests/test-strftime.c b/tests/test-strftime.c
index c7df5f0..102e168 100644
--- a/tests/test-strftime.c
+++ b/tests/test-strftime.c
@@ -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 }
};
--
2.7.4
Loading...