[v4] Fix strptime era handling, add more era tests [BZ #24394]

Message ID xnbm1upd30.fsf@greed.delorie.com
State Superseded
Headers

Commit Message

DJ Delorie March 29, 2019, 3:35 a.m. UTC
  Added the BCE/CE transition.  I won't guarantee that the day of the week
is correct for that one; I used what strftime returned.  I'm not testing
the day of week code here ;-)

Updated the strptime comment.

----

Test the transition points between all the currently listed Japanese
era name changes. This includes testing the transition between the
first year date and the second year date. This test will help test
the upcoming Japanese era name change.

Also fixes a fencepost error where the era name isn't properly parsed
by strptime in the last (partial) year of the era.

Example: if an era change happens in Feb 1990, and again in Aug 1995,
that's 5.5 years long, but the 0.5 year wasn't accounted for.
  

Comments

TAMUKI Shoichi March 29, 2019, 6:50 a.m. UTC | #1
Hello DJ Delorie-san,

Thank you for creating this test case.

From: DJ Delorie <dj@redhat.com>
Subject: [v4] Fix strptime era handling, add more era tests [BZ #24394]
Date: Thu, 28 Mar 2019 23:35:31 -0400

> diff --git a/ChangeLog b/ChangeLog
> index bd76c1e28d..db33d8a6a3 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,10 @@
> +2019-03-28  DJ Delorie  <dj@redhat.com>
> +
> +	[BZ #24394]
> +	* time/strptime_l.c (%Ey): Fix fencepost error.
> +	* time/tst-strftime3.c: New.
> +	* time/Makefile (tests): Add tst-strftime3.

This test case is intended to check whether strptime can correctly
parse %EY, so it would be nice to rename it to tst-strptime4.c.

The test case to check whether strftime can correctly format %EY
already exists as tst-strftime2.c.  This covers ja_JP, lo_LA, th_TH,
zh_TW, cmn_TW, hak_TW, nan_TW, and lzh_TW.  Regarding *_TW, Rafal-san
is preparing a patch.

In addition to ja_JP locale, I think it is necessary to check the
locale of other countries, in particular *_TW locale.

What about the consideration of %EY, %_EY, and %-EY?

How does it behave if specifying a non-existent date, such as:

Heisei gan nen 01 gatsu 07 nichi
Showa   64 nen 01 gatsu 08 nichi

I think that these tests are also necessary.

Regards,
TAMUKI Shoichi
  
Rafal Luzynski March 29, 2019, 11:13 a.m. UTC | #2
29.03.2019 07:50 TAMUKI Shoichi <tamuki@linet.gr.jp> wrote:
> [...]
> From: DJ Delorie <dj@redhat.com>
> Subject: [v4] Fix strptime era handling, add more era tests [BZ #24394]
> Date: Thu, 28 Mar 2019 23:35:31 -0400
> 
> > diff --git a/ChangeLog b/ChangeLog
> > index bd76c1e28d..db33d8a6a3 100644
> > --- a/ChangeLog
> > +++ b/ChangeLog
> > @@ -1,3 +1,10 @@
> > +2019-03-28  DJ Delorie  <dj@redhat.com>
> > +
> > +	[BZ #24394]
> > +	* time/strptime_l.c (%Ey): Fix fencepost error.
> > +	* time/tst-strftime3.c: New.
> > +	* time/Makefile (tests): Add tst-strftime3.
> 
> This test case is intended to check whether strptime can correctly
> parse %EY, so it would be nice to rename it to tst-strptime4.c.

This is exactly what I was going to say.  Thank you for raising
it in public first.

> [...] Regarding *_TW, Rafal-san
> is preparing a patch.

That's true.  As always, my free time is limited so if anybody finds
my work too slow and wants to take the task I'm always open to this.

> In addition to ja_JP locale, I think it is necessary to check the
> locale of other countries, in particular *_TW locale.

This sounds good but also we can add other locales later.

> What about the consideration of %EY, %_EY, and %-EY?

As far as I know these flags should be ignored and all potential
input strings (no matter if they are zero-padded, space-padded
or no padded at all) should be accepted by any of these format
specifiers.  At least that was the rule when I was adding a support
of "%OB"/"%Ob"/"%Oh": all format specifiers should accept all
potentially possible forms of a month name.

Of course, we may add tests to verify if these flags are correctly
ignored and all potential valid inputs are parsed correctly but
I don't have a strong desire to implement this.

> How does it behave if specifying a non-existent date, such as:
> 
> Heisei gan nen 01 gatsu 07 nichi
> Showa   64 nen 01 gatsu 08 nichi
> 
> I think that these tests are also necessary.

I think we can't implement this without your help.

Thank you for your feedback, best regards,

Rafal
  
Rafal Luzynski March 29, 2019, 11:50 a.m. UTC | #3
Hello DJ,

Thank you for your contribution.  My review is incomplete but
as far as I can see Carlos has already done a great job here.
This is only an additional feedback. Please see below.

29.03.2019 04:35 DJ Delorie <dj@redhat.com> wrote:
> [...]
> Added the BCE/CE transition.  I won't guarantee that the day of the week
> is correct for that one; I used what strftime returned.  I'm not testing
> the day of week code here ;-)

Do we need to initialize any weekday number at all?  It's difficult
to figure out the correct weekday number for past dates without using
a calendar.

> [...]
> diff --git a/time/Makefile b/time/Makefile
> index 5c6304ece1..2ca206309d 100644
> --- a/time/Makefile
> +++ b/time/Makefile
> @@ -43,7 +43,7 @@ tests	:= test_time clocktest tst-posixtz tst-strptime
> tst_wcsftime \
>  	   tst-getdate tst-mktime tst-mktime2 tst-ftime_l tst-strftime \
>  	   tst-mktime3 tst-strptime2 bug-asctime bug-asctime_r bug-mktime1 \
>  	   tst-strptime3 bug-getdate1 tst-strptime-whitespace tst-ftime \
> -	   tst-tzname tst-y2039 bug-mktime4 tst-strftime2
> +	   tst-tzname tst-y2039 bug-mktime4 tst-strftime2 tst-strftime3
>  
>  include ../Rules
>  

Correct, this Makefile already generates all necessary locales.
No need to add more.

> [...]
> diff --git a/time/tst-strftime3.c b/time/tst-strftime3.c
> new file mode 100644
> index 0000000000..ac5ddf7b80
> --- /dev/null
> +++ b/time/tst-strftime3.c
> @@ -0,0 +1,433 @@
> +/* Test for strftime, esp Japenese era name changes.

Is "esp" a shortcut for "especially"?  Unless I am the only one confused
here, would you mind using the full version?

> [...]
> +/* These exist for the convenience of writing the test data, because
> +   zero-based vs one-based.  */
> +typedef enum {
> +  Sun, Mon, Tue, Wed, Thu, Fri, Sat
> +} WeekDay;
> +
> +typedef enum {
> +  Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
> +} Month;

This pattern is excellent.  I hope you don't mind that I use for
the other tests for strftime() which I'm currently working on.

> [...]
> +const Data data[] = {
> +
> +  { "Baseline test",
> +    2019, Mar, 27, Wed, 14,  3, 22, "en_US.ISO-8859-1", "%Y-%m-%d %T",
> +    "2019-03-27 14:03:22" },
> +
> +
> +  { "Japanese era change, BCE/CE, before transition",
> +    0, Dec,  31, Sun, 12, 00, 00, "ja_JP.UTF-8", "%EY",

Do we need two ^ spaces here and three spaces in the dates where
a day number is one-digit?  If not, can you please remove one space?

> +/* Helper function to create a printable version of struct tm.  */
> +static void
> +tm_to_printed (struct tm *tm, char *buffer)
> +{
> +  snprintf (buffer, TMBUFLEN, "%04d/%02d/%02d-%02d:%02d:%02d-%d",
> +	    tm->tm_year,
> +	    tm->tm_mon,
> +	    tm->tm_mday,
> +	    tm->tm_hour,
> +	    tm->tm_min,
> +	    tm->tm_sec,
> +	    tm->tm_wday);
> +}

Would it be helpful to print the weekday name (even abbreviated)
instead of a weekday number which may be confusing? Suggestion:

const char *weekday_name[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri",
"Sat" };

[...]

  snprintf (buffer, TMBUFLEN, "%04d/%02d/%02d-%02d:%02d:%02d, %s",
	    tm->tm_year,
	    tm->tm_mon,
	    tm->tm_mday,
	    tm->tm_hour,
	    tm->tm_min,
	    tm->tm_sec,
	    weekday_name[tm->tm_wday]);

What about a space rather than a dash between a day number and an hour?

> +static int
> +do_test (void)
> +{
> [...]
> +      /* Print this just to help debug failures.  */
> +      printf("%s: %s %s %s\n", d->name, d->locale, d->format,
> d->printed);

This often produces the lines which exceed 80 columns.  Can we
have a linebreak in the middle?  Suggestions:

      printf("%s:\n%s %s %s\n", d->name, d->locale, d->format, d->printed);

or

      printf("%s: %s\n%s %s\n", d->name, d->locale, d->format, d->printed);

or any other variant.  Additional tabs or spaces are welcome as well.

Will it be easy to add more locales and more calendars to this test file?
I think it is possible but I'm also thinking on whether it can be easier.
No suggestion from me at the moment, feel free not to change anything
if you don't have any suggestion either.

Regards,

Rafal
  
Carlos O'Donell March 29, 2019, 2:53 p.m. UTC | #4
On 3/29/19 2:50 AM, TAMUKI Shoichi wrote:
> Hello DJ Delorie-san,
> 
> Thank you for creating this test case.
> 
> From: DJ Delorie <dj@redhat.com>
> Subject: [v4] Fix strptime era handling, add more era tests [BZ #24394]
> Date: Thu, 28 Mar 2019 23:35:31 -0400
> 
>> diff --git a/ChangeLog b/ChangeLog
>> index bd76c1e28d..db33d8a6a3 100644
>> --- a/ChangeLog
>> +++ b/ChangeLog
>> @@ -1,3 +1,10 @@
>> +2019-03-28  DJ Delorie  <dj@redhat.com>
>> +
>> +	[BZ #24394]
>> +	* time/strptime_l.c (%Ey): Fix fencepost error.
>> +	* time/tst-strftime3.c: New.
>> +	* time/Makefile (tests): Add tst-strftime3.
> 
> This test case is intended to check whether strptime can correctly
> parse %EY, so it would be nice to rename it to tst-strptime4.c.

Agreed. Good catch.

> The test case to check whether strftime can correctly format %EY
> already exists as tst-strftime2.c.  This covers ja_JP, lo_LA, th_TH,
> zh_TW, cmn_TW, hak_TW, nan_TW, and lzh_TW.  Regarding *_TW, Rafal-san
> is preparing a patch.

The *most important* thing for me is that ja_JP get coverage of the
possible interface uses for the upcoming era name change.

I suggest we focus *only* on ja_JP locale today, and get the new test
in place to test the April 1st new era name change.

> In addition to ja_JP locale, I think it is necessary to check the
> locale of other countries, in particular *_TW locale.

Agreed. We can add these later.
  
> What about the consideration of %EY, %_EY, and %-EY?

Agreed. We can add these later.

For now I think testing %EY is the single most useful thing, and I
think we could accept the patch just for that.

> How does it behave if specifying a non-existent date, such as:
> 
> Heisei gan nen 01 gatsu 07 nichi
> Showa   64 nen 01 gatsu 08 nichi
> 
> I think that these tests are also necessary.

As Rafal points out I think we could use your help there. If we
accept DJ's patch then you could work on top of that to add a few
more test cases to check invalid tests?

Again, I'm keen to get DJ's test clean and working for the era
name change to test the transition points.
  
TAMUKI Shoichi March 30, 2019, 12:50 p.m. UTC | #5
Hello Rafal-san,

From: Rafal Luzynski <digitalfreak@lingonborough.com>
Subject: Re: [v4] Fix strptime era handling, add more era tests [BZ #24394]
Date: Fri, 29 Mar 2019 12:13:49 +0100 (CET)

> > [...] Regarding *_TW, Rafal-san
> > is preparing a patch.
> 
> That's true.  As always, my free time is limited so if anybody finds
> my work too slow and wants to take the task I'm always open to this.

OK.  I will help you as much as possible. :-)

> > In addition to ja_JP locale, I think it is necessary to check the
> > locale of other countries, in particular *_TW locale.
> 
> This sounds good but also we can add other locales later.
> 
> > What about the consideration of %EY, %_EY, and %-EY?
> 
> As far as I know these flags should be ignored and all potential
> input strings (no matter if they are zero-padded, space-padded
> or no padded at all) should be accepted by any of these format
> specifiers.  At least that was the rule when I was adding a support
> of "%OB"/"%Ob"/"%Oh": all format specifiers should accept all
> potentially possible forms of a month name.
> 
> Of course, we may add tests to verify if these flags are correctly
> ignored and all potential valid inputs are parsed correctly but
> I don't have a strong desire to implement this.

OK.

> > How does it behave if specifying a non-existent date, such as:
> > 
> > Heisei gan nen 01 gatsu 07 nichi
> > Showa   64 nen 01 gatsu 08 nichi
> > 
> > I think that these tests are also necessary.
> 
> I think we can't implement this without your help.

In the social life, the former can hardly occur, but the latter can
happen in reality.

Regards,
TAMUKI Shoichi
  
TAMUKI Shoichi March 30, 2019, 12:51 p.m. UTC | #6
Hello Carlos-san,

From: Carlos O'Donell <codonell@redhat.com>
Subject: Re: [v4] Fix strptime era handling, add more era tests [BZ #24394]
Date: Fri, 29 Mar 2019 10:53:09 -0400

> > The test case to check whether strftime can correctly format %EY
> > already exists as tst-strftime2.c.  This covers ja_JP, lo_LA, th_TH,
> > zh_TW, cmn_TW, hak_TW, nan_TW, and lzh_TW.  Regarding *_TW, Rafal-san
> > is preparing a patch.
> 
> The *most important* thing for me is that ja_JP get coverage of the
> possible interface uses for the upcoming era name change.
> 
> I suggest we focus *only* on ja_JP locale today, and get the new test
> in place to test the April 1st new era name change.

Agreed.

> > In addition to ja_JP locale, I think it is necessary to check the
> > locale of other countries, in particular *_TW locale.
> 
> Agreed. We can add these later.
>   
> > What about the consideration of %EY, %_EY, and %-EY?
> 
> Agreed. We can add these later.
> 
> For now I think testing %EY is the single most useful thing, and I
> think we could accept the patch just for that.

Agreed.

> > How does it behave if specifying a non-existent date, such as:
> > 
> > Heisei gan nen 01 gatsu 07 nichi
> > Showa   64 nen 01 gatsu 08 nichi
> > 
> > I think that these tests are also necessary.
> 
> As Rafal points out I think we could use your help there. If we
> accept DJ's patch then you could work on top of that to add a few
> more test cases to check invalid tests?

Yes, I can contribute as needed.  Since it is expected that the
response to the new era of some systems is delayed, I think that there
is a case to parse non-existent date.  According to the Japanese
government, the use of "H31.5.1", "H31.8.12", etc. are permitted for a
certain period of time.

Regards,
TAMUKI Shoichi
  
Carlos O'Donell March 31, 2019, 3:03 a.m. UTC | #7
On 3/30/19 8:51 AM, TAMUKI Shoichi wrote:
> Hello Carlos-san,
> 
> From: Carlos O'Donell <codonell@redhat.com>
> Subject: Re: [v4] Fix strptime era handling, add more era tests [BZ #24394]
> Date: Fri, 29 Mar 2019 10:53:09 -0400
> 
>>> The test case to check whether strftime can correctly format %EY
>>> already exists as tst-strftime2.c.  This covers ja_JP, lo_LA, th_TH,
>>> zh_TW, cmn_TW, hak_TW, nan_TW, and lzh_TW.  Regarding *_TW, Rafal-san
>>> is preparing a patch.
>>
>> The *most important* thing for me is that ja_JP get coverage of the
>> possible interface uses for the upcoming era name change.
>>
>> I suggest we focus *only* on ja_JP locale today, and get the new test
>> in place to test the April 1st new era name change.
> 
> Agreed.
> 
>>> In addition to ja_JP locale, I think it is necessary to check the
>>> locale of other countries, in particular *_TW locale.
>>
>> Agreed. We can add these later.
>>    
>>> What about the consideration of %EY, %_EY, and %-EY?
>>
>> Agreed. We can add these later.
>>
>> For now I think testing %EY is the single most useful thing, and I
>> think we could accept the patch just for that.
> 
> Agreed.
> 
>>> How does it behave if specifying a non-existent date, such as:
>>>
>>> Heisei gan nen 01 gatsu 07 nichi
>>> Showa   64 nen 01 gatsu 08 nichi
>>>
>>> I think that these tests are also necessary.
>>
>> As Rafal points out I think we could use your help there. If we
>> accept DJ's patch then you could work on top of that to add a few
>> more test cases to check invalid tests?
> 
> Yes, I can contribute as needed.  Since it is expected that the
> response to the new era of some systems is delayed, I think that there
> is a case to parse non-existent date.  According to the Japanese
> government, the use of "H31.5.1", "H31.8.12", etc. are permitted for a
> certain period of time.

I'm sorry I'm not familiar with "H31.5.1", or "H31.8.12", what are they
and how do they apply?
  
TAMUKI Shoichi March 31, 2019, 4:53 a.m. UTC | #8
Hello Carlos-san,

From: Carlos O'Donell <codonell@redhat.com>
Subject: Re: [v4] Fix strptime era handling, add more era tests [BZ #24394]
Date: Sat, 30 Mar 2019 23:03:12 -0400

> > > As Rafal points out I think we could use your help there. If we
> > > accept DJ's patch then you could work on top of that to add a few
> > > more test cases to check invalid tests?
> > 
> > Yes, I can contribute as needed.  Since it is expected that the
> > response to the new era of some systems is delayed, I think that there
> > is a case to parse non-existent date.  According to the Japanese
> > government, the use of "H31.5.1", "H31.8.12", etc. are permitted for a
> > certain period of time.
> 
> I'm sorry I'm not familiar with "H31.5.1", or "H31.8.12", what are they
> and how do they apply?

Sorry.  These above are abbreviations of era and have not yet been
implemented in Glibc.

So, they mean as below:
"Heisei 31 nen 05 gatsu 01 nichi",
"Heisei 31 nen 08 gatsu 12 nichi"

Correctly, these should be:

"(new era) gan nen 05 gatsu 01 nichi",
"(nes era) gan nen 08 gatsu 12 nichi"

Regards,
TAMUKI Shoichi
  
Andreas Schwab April 2, 2019, 7:05 a.m. UTC | #9
https://build.opensuse.org/package/live_build_log/home:Andreas_Schwab:glibc/glibc:testsuite/f/i586
https://build.opensuse.org/package/live_build_log/home:Andreas_Schwab:glibc/glibc:testsuite/p/ppc

tst-strftime3.c: In function 'print_string_hex':
tst-strftime3.c:351:16: error: format '%X' expects argument of type 'unsigned int', but argument 2 has type 'wchar_t' {aka 'long int'} [-Werror=format=]
  printf ("<U%04X>", w[i]);
             ~~~^    ~~~~
             %04lX

Andreas.
  

Patch

diff --git a/ChangeLog b/ChangeLog
index bd76c1e28d..db33d8a6a3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@ 
+2019-03-28  DJ Delorie  <dj@redhat.com>
+
+	[BZ #24394]
+	* time/strptime_l.c (%Ey): Fix fencepost error.
+	* time/tst-strftime3.c: New.
+	* time/Makefile (tests): Add tst-strftime3.
+
 2019-02-26  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
 	* math/math.h (fpclassify, isfinite, isnormal, isnan): Use builtin for
diff --git a/time/Makefile b/time/Makefile
index 5c6304ece1..2ca206309d 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -43,7 +43,7 @@  tests	:= test_time clocktest tst-posixtz tst-strptime tst_wcsftime \
 	   tst-getdate tst-mktime tst-mktime2 tst-ftime_l tst-strftime \
 	   tst-mktime3 tst-strptime2 bug-asctime bug-asctime_r bug-mktime1 \
 	   tst-strptime3 bug-getdate1 tst-strptime-whitespace tst-ftime \
-	   tst-tzname tst-y2039 bug-mktime4 tst-strftime2
+	   tst-tzname tst-y2039 bug-mktime4 tst-strftime2 tst-strftime3
 
 include ../Rules
 
diff --git a/time/strptime_l.c b/time/strptime_l.c
index e19b9a15dd..7436a168b7 100644
--- a/time/strptime_l.c
+++ b/time/strptime_l.c
@@ -907,10 +907,15 @@  __strptime_internal (const char *rp, const char *fmt, struct tm *tmp,
 			{
 			  int delta = ((tm->tm_year - era->offset)
 				       * era->absolute_direction);
+			  /* The difference between two sets of years
+			     does not include the final year itself,
+			     therefore add 1 to the difference to
+			     account for that final year.  */
 			  match = (delta >= 0
 				   && delta < (((int64_t) era->stop_date[0]
 						- (int64_t) era->start_date[0])
-					       * era->absolute_direction));
+					       * era->absolute_direction
+					       + 1));
 			}
 		      if (! match)
 			return NULL;
@@ -928,10 +933,12 @@  __strptime_internal (const char *rp, const char *fmt, struct tm *tmp,
 			{
 			  int delta = ((tm->tm_year - era->offset)
 				       * era->absolute_direction);
+			  /* See comment above about year difference + 1.  */
 			  if (delta >= 0
 			      && delta < (((int64_t) era->stop_date[0]
 					   - (int64_t) era->start_date[0])
-					  * era->absolute_direction))
+					  * era->absolute_direction
+					  + 1))
 			    {
 			      s.decided = loc;
 			      break;
diff --git a/time/tst-strftime3.c b/time/tst-strftime3.c
new file mode 100644
index 0000000000..ac5ddf7b80
--- /dev/null
+++ b/time/tst-strftime3.c
@@ -0,0 +1,433 @@ 
+/* Test for strftime, esp Japenese era name changes.
+   Copyright (C) 2019 Free Software Foundation, Inc.  This file is
+   part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <locale.h>
+#include <wchar.h>
+
+#include <support/check.h>
+#include <array_length.h>
+
+/* These exist for the convenience of writing the test data, because
+   zero-based vs one-based.  */
+typedef enum {
+  Sun, Mon, Tue, Wed, Thu, Fri, Sat
+} WeekDay;
+
+typedef enum {
+  Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
+} Month;
+
+typedef struct Data {
+  /* A descriptive name of the test. */
+  const char *name;
+
+  /* The specific date and time to be tested.  */
+  int y, m, d;
+  WeekDay w;
+  int hh, mm, ss;
+
+  /* The locale under which the conversion is done.  */
+  const char *locale;
+
+  /* Format passed to strftime.  */
+  const char *format;
+
+  /* Expected data, NUL terminated.  */
+  const char *printed;
+
+} Data;
+
+/* Notes:
+
+   Years are full 4-digit years, the code compensates.  Likewise,
+   use month and weekday enums (above) which are zero-based.
+
+   The encoded strings are multibyte strings in the C locale which
+   reflect the same binary data as the expected strings.  When you run
+   the test, the strings are printed as-is to stdout, so if your
+   terminal is set for the correct encoding, they'll be printed
+   "correctly".  Put the Unicode codes and UTF-8 samples in the
+   comments.
+
+   For convenience, mis-matched strings are printed in
+   paste-compatible format, raw text format, and unicode format.  Use
+   "" between a hex escape sequence (like \xe8) and a following hex
+   digit which should be considered as a printable character.
+
+   To verify text, save the correct text in a file, and use "od -tx1
+   -tc file" to see the raw hex values.  */
+
+const Data data[] = {
+
+  { "Baseline test",
+    2019, Mar, 27, Wed, 14,  3, 22, "en_US.ISO-8859-1", "%Y-%m-%d %T",
+    "2019-03-27 14:03:22" },
+
+
+  { "Japanese era change, BCE/CE, before transition",
+    0, Dec,  31, Sun, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U7D00><U5143><U524D>01<U5E74> 紀元前01年 */
+    "\xe7\xb4\x80\xe5\x85\x83\xe5\x89\x8d""01\xe5\xb9\xb4" },
+  { "Japanese era change, BCE/CE, after transition",
+    1, Jan,   1, Mon, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U897F><U66A6>01<U5E74> 西暦01年 */
+    "\xe8\xa5\xbf\xe6\x9a\xa6""01\xe5\xb9\xb4" },
+
+  { "Japanese era change, BCE/CE, before transition",
+    0, Dec,  31, Sun, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U7D00><U5143><U524D>01<U5E74> 紀元前01年 */
+    "\xb5\xaa\xb8\xb5\xc1\xb0""01\xc7\xaf" },
+  { "Japanese era change, BCE/CE, after transition",
+    1, Jan,   1, Mon, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U897F><U66A6>01<U5E74> 西暦01年 */
+    "\xc0\xbe\xce\xf1""01\xc7\xaf" },
+
+
+  { "Japanese era change, 1873, before transition",
+    1872, Dec,  31, Tue, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U897F><U66A6>1872<U5E74> 西暦1872年 */
+    "\xe8\xa5\xbf\xe6\x9a\xa6""1872\xe5\xb9\xb4" },
+  { "Japanese era change, 1873, after transition",
+    1873, Jan,   1, Wed, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U660E><U6CBB>06<U5E74> 明治06年 */
+    "\xe6\x98\x8e\xe6\xb2\xbb""06\xe5\xb9\xb4" },
+
+
+  { "Japanese era change, 1873, before transition",
+    1872, Dec,  31, Tue, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U897F><U66A6>1872<U5E74> 西暦1872年 */
+    "\xc0\xbe\xce\xf1""1872\xc7\xaf" },
+  { "Japanese era change, 1873, after transition",
+    1873, Jan,   1, Wed, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U660E><U6CBB>06<U5E74> 明治06年 */
+    "\xcc\xc0\xbc\xa3""06\xc7\xaf" },
+
+
+  { "Japanese era change, 1912, before transition year",
+    1911, Dec,  31, Sun, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U660E><U6CBB>44<U5E74> 明治44年 */
+    "\xe6\x98\x8e\xe6\xb2\xbb""44\xe5\xb9\xb4" },
+  { "Japanese era change, 1912, start of transition year",
+    1912, Jan,   1, Mon, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U660E><U6CBB>45<U5E74> 明治45年 */
+    "\xe6\x98\x8e\xe6\xb2\xbb""45\xe5\xb9\xb4" },
+
+  { "Japanese era change, 1912, before transition",
+    1912, Jul,  29, Mon, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U660E><U6CBB>45<U5E74> 明治45年 */
+    "\xe6\x98\x8e\xe6\xb2\xbb""45\xe5\xb9\xb4" },
+  { "Japanese era change, 1912, after transition",
+    1912, Jul,  30, Tue, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U5927><U6B63><U5143><U5E74> 大正元年 */
+    "\xe5\xa4\xa7\xe6\xad\xa3\xe5\x85\x83\xe5\xb9\xb4" },
+
+  { "Japanese era change, 1912, before end of transition year",
+    1912, Dec,  31, Tue, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U5927><U6B63><U5143><U5E74> 大正元年 */
+    "\xe5\xa4\xa7\xe6\xad\xa3\xe5\x85\x83\xe5\xb9\xb4" },
+  { "Japanese era change, 1912, after transition year",
+    1913, Jan,   1, Wed, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U5927><U6B63>02<U5E74> 大正02年 */
+    "\xe5\xa4\xa7\xe6\xad\xa3""02\xe5\xb9\xb4" },
+
+
+  { "Japanese era change, 1912, before transition year",
+    1911, Dec,  31, Sun, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U660E><U6CBB>44<U5E74> 明治44年 */
+    "\xcc\xc0\xbc\xa3""44\xc7\xaf" },
+  { "Japanese era change, 1912, start of transition year",
+    1912, Jan,   1, Mon, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U660E><U6CBB>45<U5E74> 明治45年 */
+    "\xcc\xc0\xbc\xa3""45\xc7\xaf" },
+
+  { "Japanese era change, 1912, before transition",
+    1912, Jul,  29, Mon, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U660E><U6CBB>45<U5E74> 明治45年 */
+    "\xcc\xc0\xbc\xa3""45\xc7\xaf" },
+  { "Japanese era change, 1912, after transition",
+    1912, Jul,  30, Tue, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U5927><U6B63><U5143><U5E74> 大正元年 */
+    "\xc2\xe7\xc0\xb5\xb8\xb5\xc7\xaf" },
+
+  { "Japanese era change, 1912, before end of transition year",
+    1912, Dec,  31, Tue, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U5927><U6B63><U5143><U5E74> 大正元年 */
+    "\xc2\xe7\xc0\xb5\xb8\xb5\xc7\xaf" },
+  { "Japanese era change, 1912, after transition year",
+    1913, Jan,   1, Wed, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U5927><U6B63>02<U5E74> 大正02年 */
+    "\xc2\xe7\xc0\xb5""02\xc7\xaf" },
+
+
+  { "Japanese era change, 1926, before transition year",
+    1925, Dec,  31, Thu, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U5927><U6B63>14<U5E74> 大正14年 */
+    "\xe5\xa4\xa7\xe6\xad\xa3""14\xe5\xb9\xb4" },
+  { "Japanese era change, 1926, start of transition year",
+    1926, Jan,   1, Fri, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U5927><U6B63>15<U5E74> 大正15年 */
+    "\xe5\xa4\xa7\xe6\xad\xa3""15\xe5\xb9\xb4" },
+
+  { "Japanese era change, 1926, before transition",
+    1926, Dec,  24, Fri, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U5927><U6B63>15<U5E74> 大正15年 */
+    "\xe5\xa4\xa7\xe6\xad\xa3""15\xe5\xb9\xb4" },
+  { "Japanese era change, 1926, after transition",
+    1926, Dec,  25, Sat, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U662D><U548C><U5143><U5E74> 昭和元年 */
+    "\xe6\x98\xad\xe5\x92\x8c\xe5\x85\x83\xe5\xb9\xb4" },
+
+  { "Japanese era change, 1926, before end of transition year",
+    1926, Dec,  31, Fri, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U662D><U548C><U5143><U5E74> 昭和元年 */
+    "\xe6\x98\xad\xe5\x92\x8c\xe5\x85\x83\xe5\xb9\xb4" },
+  { "Japanese era change, 1926, after transition year",
+    1927, Jan,   1, Sat, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /*  <U662D><U548C>02<U5E74> 昭和02年 */
+    "\xe6\x98\xad\xe5\x92\x8c""02\xe5\xb9\xb4" },
+
+
+  { "Japanese era change, 1926, before transition year",
+    1925, Dec,  31, Thu, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U5927><U6B63>14<U5E74> 大正14年 */
+    "\xc2\xe7\xc0\xb5""14\xc7\xaf" },
+  { "Japanese era change, 1926, start of transition year",
+    1926, Jan,   1, Fri, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U5927><U6B63>15<U5E74> 大正15年 */
+    "\xc2\xe7\xc0\xb5""15\xc7\xaf" },
+
+  { "Japanese era change, 1926, before transition",
+    1926, Dec,  24, Fri, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U5927><U6B63>15<U5E74> 大正15年 */
+    "\xc2\xe7\xc0\xb5""15\xc7\xaf" },
+  { "Japanese era change, 1926, after transition",
+    1926, Dec,  25, Sat, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U662D><U548C><U5143><U5E74> 昭和元年 */
+    "\xbe\xbc\xcf\xc2\xb8\xb5\xc7\xaf" },
+
+  { "Japanese era change, 1926, before end of transition year",
+    1926, Dec,  31, Fri, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U662D><U548C><U5143><U5E74> 昭和元年 */
+    "\xbe\xbc\xcf\xc2\xb8\xb5\xc7\xaf" },
+  { "Japanese era change, 1926, after transition year",
+    1927, Jan,   1, Sat, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /*  <U662D><U548C>02<U5E74> 昭和02年 */
+    "\xbe\xbc\xcf\xc2""02\xc7\xaf" },
+
+
+  { "Japanese era change, 1989, before transition year",
+    1988, Dec,  31, Sat, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U662D><U548C>63<U5E74> 昭和63年 */
+    "\xe6\x98\xad\xe5\x92\x8c""63\xe5\xb9\xb4" },
+  { "Japanese era change, 1989, start of transition year",
+    1989, Jan,  1, Sun, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U662D><U548C>64<U5E74> 昭和64年 */
+    "\xe6\x98\xad\xe5\x92\x8c""64\xe5\xb9\xb4" },
+
+  { "Japanese era change, 1989, before transition",
+    1989, Jan,  7, Sat, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U662D><U548C>64<U5E74> 昭和64年 */
+    "\xe6\x98\xad\xe5\x92\x8c""64\xe5\xb9\xb4" },
+  { "Japanese era change, 1989, after transition",
+    1989, Jan,  8, Sun, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U5E73><U6210><U5143><U5E74> 平成元年 */
+    "\xe5\xb9\xb3\xe6\x88\x90\xe5\x85\x83\xe5\xb9\xb4" },
+
+  { "Japanese era change, 1989, end of transition year",
+    1989, Dec, 31, Sun, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U5E73><U6210><U5143><U5E74> 平成元年 */
+    "\xe5\xb9\xb3\xe6\x88\x90\xe5\x85\x83\xe5\xb9\xb4" },
+  { "Japanese era change, 1989, after transition year",
+    1990, Jan,  1, Mon, 12, 00, 00, "ja_JP.UTF-8", "%EY",
+    /* <U5E73><U6210>02<U5E74> 平成02年 */
+    "\xe5\xb9\xb3\xe6\x88\x90""02\xe5\xb9\xb4" },
+
+
+  { "Japanese era change, 1989, before transition year",
+    1988, Dec,  31, Sat, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U662D><U548C>63<U5E74> 昭和63年 */
+    "\xbe\xbc\xcf\xc2""63\xc7\xaf" },
+  { "Japanese era change, 1989, start of transition year",
+    1989, Jan,  1, Sun, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U662D><U548C>64<U5E74> 昭和64年 */
+    "\xbe\xbc\xcf\xc2""64\xc7\xaf" },
+
+  { "Japanese era change, 1989, before transition",
+    1989, Jan,  7, Sat, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U662D><U548C>64<U5E74> 昭和64年 */
+    "\xbe\xbc\xcf\xc2""64\xc7\xaf" },
+  { "Japanese era change, 1989, after transition",
+    1989, Jan,  8, Sun, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U5E73><U6210><U5143><U5E74> 平成元年 */
+    "\xca\xbf\xc0\xae\xb8\xb5\xc7\xaf" },
+
+  { "Japanese era change, 1989, end of transition year",
+    1989, Dec, 31, Sun, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U5E73><U6210><U5143><U5E74> 平成元年 */
+    "\xca\xbf\xc0\xae\xb8\xb5\xc7\xaf" },
+  { "Japanese era change, 1989, after transition year",
+    1990, Jan,  1, Mon, 12, 00, 00, "ja_JP.EUC-JP", "%EY",
+    /* <U5E73><U6210>02<U5E74> 平成02年 */
+    "\xca\xbf\xc0\xae""02\xc7\xaf" },
+};
+
+#define NDATA array_length(data)
+
+/* Size of buffer passed to strftime.  */
+#define STRBUFLEN 1000
+/* Size of buffer passed to tm_to_printed.  */
+#define TMBUFLEN 50
+
+/* Helper function to compare strings and print out mismatches in a
+   format suitable for maintaining this test.  TEST_COMPARE_STRINGS
+   prints out a less suitable format.  */
+
+static void
+print_string_hex (const char *header, const char *str)
+{
+  int tictoc = 0;
+  const char *s = str;
+  wchar_t w[STRBUFLEN];
+  size_t i, wlen;
+
+  printf("%s : ", header);
+
+  while (s && *s)
+    {
+      /* isgraph() equivalent, but independent of current locale.  */
+      if (' ' <= *s && *s <= '~')
+	putchar(*s);
+      else
+	{
+	  if (tictoc)
+	    printf("\033[36m");
+	  else
+	    printf("\033[31m");
+	  tictoc = ! tictoc;
+
+	  printf("\\x%02x\033[0m", (unsigned char)*s);
+	}
+
+      ++ s;
+    }
+  printf(" - %s\n", str);
+
+  s = str;
+  wlen = mbsrtowcs (w, &s, strlen (s), NULL);
+  printf("%*s", (int)strlen(header) + 3, " ");
+  for (i = 0; i < wlen && i < strlen (str); i ++)
+    {
+      if (' ' <= w[i] && w[i] <= '~')
+	putchar(w[i]);
+      else
+	printf("<U%04X>", w[i]);
+    }
+  printf("\n");
+}
+
+static void
+compare_strings (const char *got, const char *expected,
+		 const char *filename, int lineno)
+{
+  if (got && expected && strcmp (got, expected) == 0)
+    return;
+  support_record_failure ();
+  printf ("%s:%d: error: strftime output incorrect\n", filename, lineno);
+  print_string_hex ("Got", got);
+  print_string_hex ("Exp", expected);
+}
+#define COMPARE_STRINGS(g,e) compare_strings (g, e, __FILE__, __LINE__)
+
+/* Helper function to create a printable version of struct tm.  */
+static void
+tm_to_printed (struct tm *tm, char *buffer)
+{
+  snprintf (buffer, TMBUFLEN, "%04d/%02d/%02d-%02d:%02d:%02d-%d",
+	    tm->tm_year,
+	    tm->tm_mon,
+	    tm->tm_mday,
+	    tm->tm_hour,
+	    tm->tm_min,
+	    tm->tm_sec,
+	    tm->tm_wday);
+}
+
+static int
+do_test (void)
+{
+  int i;
+  char buffer[STRBUFLEN];
+  char buf1[TMBUFLEN];
+  char buf2[TMBUFLEN];
+
+  for (i = 0; i < NDATA; i ++)
+    {
+      const Data *d = &(data[i]);
+      struct tm tm;
+      struct tm tm2;
+      size_t rv;
+      char *rvp;
+
+      /* Print this just to help debug failures.  */
+      printf("%s: %s %s %s\n", d->name, d->locale, d->format, d->printed);
+
+      tm.tm_year = d->y - 1900;
+      tm.tm_mon = d->m;
+      tm.tm_mday = d->d;
+      tm.tm_wday = d->w;
+      tm.tm_hour = d->hh;
+      tm.tm_min = d->mm;
+      tm.tm_sec = d->ss;
+      tm.tm_isdst = -1;
+
+      /* LC_ALL may interfere with the snprintf in tm_to_printed.  */
+      if (setlocale (LC_TIME, d->locale) == NULL)
+	{
+	  /* See the LOCALES list in the Makefile.  */
+	  printf ("locale %s does not exist!\n", d->locale);
+	  exit (EXIT_FAILURE);
+	}
+      /* This is just for printing wide characters if there's an error.  */
+      setlocale (LC_CTYPE, d->locale);
+
+      rv = strftime (buffer, sizeof(buffer), d->format, &tm);
+
+      TEST_COMPARE (rv, strlen (d->printed));
+      COMPARE_STRINGS (buffer, d->printed);
+
+      /* Copy the original time, so that any fields not affected by
+	 the call to strptime() will match.  */
+      tm2 = tm;
+
+      rvp = strptime (d->printed, d->format, &tm2);
+
+      TEST_COMPARE_STRING (rvp, "");
+
+      tm_to_printed (&tm, buf1);
+      tm_to_printed (&tm2, buf2);
+      TEST_COMPARE_STRING (buf1, buf2);
+    }
+
+  return 0;
+}
+
+#include <support/test-driver.c>