about summary refs log tree commit diff
path: root/time/tst-strptime2.c
diff options
context:
space:
mode:
authorVincent Bernat <Vincent.Bernat@exoscale.ch>2015-09-17 09:56:13 +0200
committerMike Frysinger <vapier@gentoo.org>2015-09-18 01:17:15 -0400
commite952e1dfeb2a603ebd74ac5478a1218061ba893b (patch)
treeb87b971b154f92becba520451b6d3749c2f5ef4f /time/tst-strptime2.c
parent900f33e23eaa20c0587f5a191b632a606e7fba5d (diff)
downloadglibc-e952e1dfeb2a603ebd74ac5478a1218061ba893b.tar.gz
glibc-e952e1dfeb2a603ebd74ac5478a1218061ba893b.tar.xz
glibc-e952e1dfeb2a603ebd74ac5478a1218061ba893b.zip
time: in strptime(), make %z accept [+-]HH:MM tz [BZ #17887]
In ISO 8601, +03:30 is a valid time zone. Currently, strptime() only
parses it as a 2-digit time zone an believes this is +03:00. This change
makes it accept a single colon.
Diffstat (limited to 'time/tst-strptime2.c')
-rw-r--r--time/tst-strptime2.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/time/tst-strptime2.c b/time/tst-strptime2.c
index 3d906dec74..7fe7350024 100644
--- a/time/tst-strptime2.c
+++ b/time/tst-strptime2.c
@@ -35,7 +35,8 @@ static bool verbose;
    following fields:
      Sign field consisting of a '+' or '-' sign,
      Hours field in two decimal digits, and
-     optional Minutes field in two decimal digits.
+     optional Minutes field in two decimal digits. Optionally,
+     a ':' is used to seperate hours and minutes.
 
    This function may write test strings with minutes values outside
    the valid range 00-59.  These are invalid strings and useful for
@@ -56,7 +57,7 @@ static bool verbose;
    range of 00 to 59.  */
 
 static long int
-mkbuf (char *buf, bool neg, unsigned int hhmm, size_t ndigits)
+mkbuf (char *buf, bool neg, bool colon, unsigned int hhmm, size_t ndigits)
 {
   const int mm_max = 59;
   char sign = neg ? '-' : '+';
@@ -66,7 +67,10 @@ mkbuf (char *buf, bool neg, unsigned int hhmm, size_t ndigits)
   long int expect = LONG_MAX;
 
   i = sprintf (buf, "%s %c", dummy_string, sign);
-  snprintf (buf + i, ndigits + 1, "%04u", hhmm);
+  if (colon)
+    snprintf (buf + i, ndigits + 2, "%02u:%02u", hh, mm);
+  else
+    snprintf (buf + i, ndigits + 1, "%04u", hhmm);
 
   if (mm <= mm_max && (ndigits == 2 || ndigits == 4))
     {
@@ -177,11 +181,22 @@ do_test (void)
       {
 	/* Test both positive and negative signs.  */
 
-	expect = mkbuf (buf, false, hhmm, ndigits);
+	expect = mkbuf (buf, false, false, hhmm, ndigits);
 	result |= compare (buf, expect, nresult);
 
-	expect = mkbuf (buf, true, hhmm, ndigits);
+	expect = mkbuf (buf, true, false, hhmm, ndigits);
 	result |= compare (buf, expect, nresult);
+
+	/* Test with colon as well.  */
+
+	if (ndigits >= 3)
+	  {
+	    expect = mkbuf (buf, false, true, hhmm, ndigits);
+	    result |= compare (buf, expect, nresult);
+
+	    expect = mkbuf (buf, true, true, hhmm, ndigits);
+	    result |= compare (buf, expect, nresult);
+	  }
       }
 
   if (result > 0 || verbose)