This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Properly handle %W in strptime


This fixes the calculation of the year day when %W was used and week day
is a Sunday.

Andreas.

	[BZ #15100]
	* time/strptime_l.c (__strptime_internal): Count Sunday in a %W
	week as 6 instead of -1.
	* time/tst-strptime.c (day_tests): Add test case.

diff --git a/time/strptime_l.c b/time/strptime_l.c
index 89daffa..a88b375 100644
--- a/time/strptime_l.c
+++ b/time/strptime_l.c
@@ -1180,8 +1180,8 @@ __strptime_internal (rp, fmt, tmp, statep LOCALE_PARAM)
 
       if (!s.have_yday)
 	tm->tm_yday = ((7 - (tm->tm_wday - w_offset)) % 7
-		       + (s.week_no - 1) *7
-		       + save_wday - w_offset);
+		       + (s.week_no - 1) * 7
+		       + (save_wday - w_offset + 7) % 7);
 
       if (!s.have_mday || !s.have_mon)
 	{
diff --git a/time/tst-strptime.c b/time/tst-strptime.c
index 12b084d..21fbb63 100644
--- a/time/tst-strptime.c
+++ b/time/tst-strptime.c
@@ -41,6 +41,7 @@ static const struct
   { "C", "19990502123412", "%Y%m%d%H%M%S", 0, 121, 4, 2 },
   { "C", "2001 20 Mon", "%Y %U %a", 1, 140, 4, 21 },
   { "C", "2001 21 Mon", "%Y %W %a", 1, 140, 4, 21 },
+  { "C", "2012 00 Sun", "%Y %W %a", 0, 0, 0, 1 },
   { "ja_JP.EUC-JP", "2000-01-01 08:12:21 AM", "%Y-%m-%d %I:%M:%S %p",
     6, 0, 0, 1 },
   { "en_US.ISO-8859-1", "2000-01-01 08:12:21 PM", "%Y-%m-%d %I:%M:%S %p",
-- 
1.8.2.1

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]