* [PATCH] strftime: fix %y format
@ 2016-07-25 19:56 Julien Ramseier
0 siblings, 0 replies; only message in thread
From: Julien Ramseier @ 2016-07-25 19:56 UTC (permalink / raw)
To: musl
The following patch fixes the '%y' format in strftime/wcsftime
when using negative tm_year values.
Results:
tm_year year before after
-----------------------------------------
-2901 -1001 "-1" "01"
-2900 -1000 "00" "00"
-2899 -999 "-99" "99"
-901 999 "-1" "99"
-900 1000 "00" "00"
-899 1001 "-99" "01"
-1 1899 "-1" "99"
0 1900 "00" "00"
1 1901 "01" "01"
---
src/time/strftime.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/time/strftime.c b/src/time/strftime.c
index f1ccc4d..a303920 100644
--- a/src/time/strftime.c
+++ b/src/time/strftime.c
@@ -166,7 +166,8 @@ const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm *
item = T_FMT;
goto nl_strftime;
case 'y':
- val = tm->tm_year % 100;
+ val = (tm->tm_year + 1900LL) % 100;
+ if (val < 0) val = -val;
goto number;
case 'Y':
val = tm->tm_year + 1900LL;
--
2.9.2
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2016-07-25 19:56 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-25 19:56 [PATCH] strftime: fix %y format Julien Ramseier
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).