This thread contains a patchset. You're looking at the original emails,
but you may wish to use the patch review UI.
Review patch
4
3
[PATCH hare] datetime: Add support for parsing timezone offset
From: "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
References: https://todo.sr.ht/~sircmpwn/hare/647
Signed-off-by: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
---
datetime/parse.ha | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/datetime/parse.ha b/datetime/parse.ha
index 29b318d4..820a0dff 100644
--- a/datetime/parse.ha
+++ b/datetime/parse.ha
@@ -144,8 +144,24 @@ export fn parse(build: *builder, layout: str, s: str) (void | invalid) = {
case 'Y' =>
build.year = get_max_n_digits(&s_iter, 4)?;
case 'z' =>
- // TODO
- continue;
+ const rest = strings::iterstr(&s_iter);
+ if(strings::hasprefix(rest, 'Z') || strings::hasprefix(rest, 'z')) {
+ build.zone.zoffset = 0;
+ } else {
+ const prefix = strings::next(&s_iter);
+ build.zone.zoffset = get_max_n_digits(&s_iter, 2)? * 100;
+
+ const rest = strings::iterstr(&s_iter);
+ if(strings::hasprefix(rest, ":")) {
+ strings::next(&s_iter);
+ };
+
+ build.zone.zoffset += get_max_n_digits(&s_iter, 2)?;
+
+ if(prefix == '-') {
+ build.zone.zoffset *= -1;
+ };
+ };
case '%' =>
eat_one_rune(&s_iter, '%')?;
--
2.35.1
[hare/patches] build success
On Tue Jun 21, 2022 at 5:07 AM BST, Haelwenn (lanodan) Monnier wrote:
> From: "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
-%<-
> case 'z' =>
-%<-
> + const rest = strings::iterstr(&s_iter);
> + if(strings::hasprefix(rest, 'Z') || strings::hasprefix(rest, 'z')) {
> + build.zone.zoffset = 0;
> + } else {
> + const prefix = strings::next(&s_iter);
> + build.zone.zoffset = get_max_n_digits(&s_iter, 2)? * 100;
> +
> + const rest = strings::iterstr(&s_iter);
> + if(strings::hasprefix(rest, ":")) {
> + strings::next(&s_iter);
> + };
> +
> + build.zone.zoffset += get_max_n_digits(&s_iter, 2)?;
> +
> + if(prefix == '-') {
> + build.zone.zoffset *= -1;
> + };
> + };
-%<-
You've got the right idea here, but:
* [[datetime::datetime]].zone.zoffset is of type [[time::duration]],
which is in nanoseconds. You're entering... minutes I think?
* Consequently, the `* 100` and implicit `* 1` need reappropriating.
Probably `* time::HOUR` and `* time::MINTUE`.
[PATCH hare v2] datetime: Add support for timezone offset
From: "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
References: https://todo.sr.ht/~sircmpwn/hare/647
Signed-off-by: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
---
datetime/parse.ha | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/datetime/parse.ha b/datetime/parse.ha
index 29b318d4..060e25ad 100644
--- a/datetime/parse.ha
+++ b/datetime/parse.ha
@@ -4,6 +4,7 @@
// (c) 2021-2022 Vlad-Stefan Harbuz <vlad@vladh.net>
use errors;
use strings;
+use time;
// Parses a date/time string into a [[builder]], according to a layout format
// string with specifiers as documented under [[format]]. Partial, sequential,
@@ -144,8 +145,24 @@ export fn parse(build: *builder, layout: str, s: str) (void | invalid) = {
case 'Y' =>
build.year = get_max_n_digits(&s_iter, 4)?;
case 'z' =>
- // TODO
- continue;
+ const rest = strings::iterstr(&s_iter);
+ if(strings::hasprefix(rest, 'Z') || strings::hasprefix(rest, 'z')) {
+ build.zone.zoffset = 0;
+ } else {
+ const prefix = strings::next(&s_iter);
+ build.zone.zoffset = get_max_n_digits(&s_iter, 2)? * time::HOUR;
+
+ const rest = strings::iterstr(&s_iter);
+ if(strings::hasprefix(rest, ":")) {
+ strings::next(&s_iter);
+ };
+
+ build.zone.zoffset += get_max_n_digits(&s_iter, 2)? * time::MINUTE;
+
+ if(prefix == '-') {
+ build.zone.zoffset *= -1;
+ };
+ };
case '%' =>
eat_one_rune(&s_iter, '%')?;
--
2.35.1
Re: [PATCH hare v2] datetime: Add support for timezone offset
Thank you!
To git@git.sr.ht:~sircmpwn/hare
f6477790..65449ddb master -> master
Applied as:
commit 65449ddbbbf39659bfaf84a2cb78510409a4ab7a
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Tue Jun 21 22:52:01 2022 +0200
datetime: add %z parsing (zone offset)
References: https://todo.sr.ht/~sircmpwn/hare/647
Signed-off-by: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
since it's not technically "timezone offset".