From: Julien Ramseier <j.ramseier@gmail.com>
To: musl@lists.openwall.com
Subject: [PATCH] strftime: fix %y format
Date: Mon, 25 Jul 2016 21:56:25 +0200 [thread overview]
Message-ID: <9F9B8A2F-E99E-4F88-94BF-26BF4A737DDE@gmail.com> (raw)
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
reply other threads:[~2016-07-25 19:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9F9B8A2F-E99E-4F88-94BF-26BF4A737DDE@gmail.com \
--to=j.ramseier@gmail.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).