* [PATCH] strptime: add support for %z field descriptor (ISO 8601 timezone)
@ 2018-07-25 10:43 Rafał Miłecki
2018-07-25 10:50 ` Rafał Miłecki
0 siblings, 1 reply; 2+ messages in thread
From: Rafał Miłecki @ 2018-07-25 10:43 UTC (permalink / raw)
To: musl; +Cc: Rafał Miłecki
From: Rafał Miłecki <rafal@milecki.pl>
This is glibc extension for parsing ISO 8601 formatted timezone offset.
Supported formats are: ±hh:mm, ±hhmm and ±hh.
While strptime() contains some helpers for parsing (e.g. numeric_range
and numeric_digits) they couldn't be used for %z due to a bigger
complexity of that field (two numbers, optional separator).
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
src/time/strptime.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/src/time/strptime.c b/src/time/strptime.c
index c54a0d8c..f3607bd0 100644
--- a/src/time/strptime.c
+++ b/src/time/strptime.c
@@ -154,6 +154,25 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
adj = 1900;
want_century = 0;
goto numeric_digits;
+ case 'z':
+ w=2;
+ if (*s == '+') s++;
+ else if (*s == '-') neg=1, s++;
+ else return 0;
+ tm->__tm_gmtoff = 0;
+ for (i=0; i<2 && isdigit(*s); i++)
+ tm->__tm_gmtoff = tm->__tm_gmtoff * 10 + *s++ - '0';
+ if (*s == ':' || isdigit(*s)) {
+ if (*s == ':') s++;
+ for (i=0; i<2 && isdigit(*s); i++)
+ tm->__tm_gmtoff = tm->__tm_gmtoff * 10 + *s++ - '0';
+ } else {
+ tm->__tm_gmtoff *= 100;
+ }
+ tm->__tm_gmtoff = tm->__tm_gmtoff / 100 * 60 + tm->__tm_gmtoff % 100;
+ tm->__tm_gmtoff *= 60;
+ if (neg) tm->__tm_gmtoff = -tm->__tm_gmtoff;
+ break;
case '%':
if (*s++ != '%') return 0;
break;
--
2.13.7
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] strptime: add support for %z field descriptor (ISO 8601 timezone)
2018-07-25 10:43 [PATCH] strptime: add support for %z field descriptor (ISO 8601 timezone) Rafał Miłecki
@ 2018-07-25 10:50 ` Rafał Miłecki
0 siblings, 0 replies; 2+ messages in thread
From: Rafał Miłecki @ 2018-07-25 10:50 UTC (permalink / raw)
To: musl; +Cc: Rafał Miłecki
On Wed, 25 Jul 2018 at 12:43, Rafał Miłecki <zajec5@gmail.com> wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
>
> This is glibc extension for parsing ISO 8601 formatted timezone offset.
> Supported formats are: ±hh:mm, ±hhmm and ±hh.
>
> While strptime() contains some helpers for parsing (e.g. numeric_range
> and numeric_digits) they couldn't be used for %z due to a bigger
> complexity of that field (two numbers, optional separator).
>
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
I found (when Googling) two people looking for that extension just
like me. One of these questions was asked back in 2015 [0] and the
reply was "it seems to be a reasonable extension" so I thought I'll
give it a try. I hope can consider adding support for that %z
extension.
[0] http://h206.n179.cust.dataforce.net/lists/musl/2015/08/14/7
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-07-25 10:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-25 10:43 [PATCH] strptime: add support for %z field descriptor (ISO 8601 timezone) Rafał Miłecki
2018-07-25 10:50 ` Rafał Miłecki
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).