about summary refs log tree commit diff
path: root/time/strftime_l.c
diff options
context:
space:
mode:
authorTAMUKI Shoichi <tamuki@linet.gr.jp>2019-01-24 23:04:12 +0900
committerTAMUKI Shoichi <tamuki@linet.gr.jp>2019-01-24 23:04:12 +0900
commit32f600a27275ec7a315cbbc465cb19b06b44f9b8 (patch)
treeafb54923738a2adab619d19877e20707663127a0 /time/strftime_l.c
parentb22eed371086b297adf9c1509850649de883d77b (diff)
downloadglibc-32f600a27275ec7a315cbbc465cb19b06b44f9b8.tar.gz
glibc-32f600a27275ec7a315cbbc465cb19b06b44f9b8.tar.xz
glibc-32f600a27275ec7a315cbbc465cb19b06b44f9b8.zip
strftime: Pass the additional flags from "%EY" to "%Ey" [BZ #24096]
The full representation of the alternative calendar year (%EY)
typically includes an internal use of "%Ey".  As a GNU extension,
apply any flags on "%EY" (e.g. "%_EY", "%-EY") to the internal "%Ey",
allowing users of "%EY" to control how the year is padded.

Reviewed-by: Rafal Luzynski <digitalfreak@lingonborough.com>
Reviewed-by: Zack Weinberg <zackw@panix.com>

ChangeLog:

	[BZ #24096]
	* manual/time.texi (strftime): Document "%EC" and "%EY".
	* time/Makefile (tests): Add tst-strftime2.
	(LOCALES): Add ja_JP.UTF-8, lo_LA.UTF-8, and th_TH.UTF-8.
	* time/strftime_l.c (__strftime_internal): Add argument yr_spec to
	override padding for "%Ey".
	If an optional flag ('_' or '-') is specified to "%EY", interpret the
	"%Ey" in the subformat as if decorated with that flag.
	* time/tst-strftime2.c: New file.
Diffstat (limited to 'time/strftime_l.c')
-rw-r--r--time/strftime_l.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/time/strftime_l.c b/time/strftime_l.c
index cbe08e7afb..cb3b8d36f6 100644
--- a/time/strftime_l.c
+++ b/time/strftime_l.c
@@ -434,7 +434,7 @@ static CHAR_T const month_name[][10] =
 #endif
 
 static size_t __strftime_internal (CHAR_T *, size_t, const CHAR_T *,
-				   const struct tm *, bool *
+				   const struct tm *, int, bool *
 				   ut_argument_spec
 				   LOCALE_PARAM) __THROW;
 
@@ -457,7 +457,7 @@ my_strftime (CHAR_T *s, size_t maxsize, const CHAR_T *format,
   tp = &tmcopy;
 #endif
   bool tzset_called = false;
-  return __strftime_internal (s, maxsize, format, tp, &tzset_called
+  return __strftime_internal (s, maxsize, format, tp, 0, &tzset_called
 			      ut_argument LOCALE_ARG);
 }
 #ifdef _LIBC
@@ -466,7 +466,7 @@ libc_hidden_def (my_strftime)
 
 static size_t
 __strftime_internal (CHAR_T *s, size_t maxsize, const CHAR_T *format,
-		     const struct tm *tp, bool *tzset_called
+		     const struct tm *tp, int yr_spec, bool *tzset_called
 		     ut_argument_spec LOCALE_PARAM)
 {
 #if defined _LIBC && defined USE_IN_EXTENDED_LOCALE_MODEL
@@ -838,11 +838,11 @@ __strftime_internal (CHAR_T *s, size_t maxsize, const CHAR_T *format,
 	  {
 	    CHAR_T *old_start = p;
 	    size_t len = __strftime_internal (NULL, (size_t) -1, subfmt,
-					      tp, tzset_called ut_argument
-					      LOCALE_ARG);
+					      tp, yr_spec, tzset_called
+					      ut_argument LOCALE_ARG);
 	    add (len, __strftime_internal (p, maxsize - i, subfmt,
-					   tp, tzset_called ut_argument
-					   LOCALE_ARG));
+					   tp, yr_spec, tzset_called
+					   ut_argument LOCALE_ARG));
 
 	    if (to_uppcase)
 	      while (old_start < p)
@@ -1273,6 +1273,8 @@ __strftime_internal (CHAR_T *s, size_t maxsize, const CHAR_T *format,
 # else
 		  subfmt = era->era_format;
 # endif
+		  if (pad != 0)
+		    yr_spec = pad;
 		  goto subformat;
 		}
 #else
@@ -1294,6 +1296,8 @@ __strftime_internal (CHAR_T *s, size_t maxsize, const CHAR_T *format,
 	      if (era)
 		{
 		  int delta = tp->tm_year - era->start_date[0];
+		  if (yr_spec != 0)
+		    pad = yr_spec;
 		  DO_NUMBER (2, (era->offset
 				 + delta * era->absolute_direction));
 		}