~sircmpwn/hare-dev

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

Details
Message ID
<20220621040704.17285-1-contact+sr.ht@hacktivis.me>
DKIM signature
missing
Download raw message
Patch: +18 -2
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

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CKVIORDOKKM5.28HXQQAEJH20X@cirno>
In-Reply-To
<20220621040704.17285-1-contact+sr.ht@hacktivis.me> (view parent)
DKIM signature
missing
Download raw message
hare/patches: SUCCESS in 1m36s

[datetime: Add support for parsing timezone offset][0] from [Haelwenn (lanodan) Monnier][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/33160
[1]: contact+sr.ht@hacktivis.me

✓ #784408 SUCCESS hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/784408
✓ #784409 SUCCESS hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/784409
Details
Message ID
<CKVWZTMD20IU.2Y8QDY0FIKXKV@ace>
In-Reply-To
<20220621040704.17285-1-contact+sr.ht@hacktivis.me> (view parent)
DKIM signature
missing
Download raw message
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

Details
Message ID
<20220621205201.3162-1-contact+sr.ht@hacktivis.me>
In-Reply-To
<CKVWZTMD20IU.2Y8QDY0FIKXKV@ace> (view parent)
DKIM signature
missing
Download raw message
Patch: +19 -2
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

Details
Message ID
<CKW4MMFX2O3D.RT2PPSI4OM1C@ace>
In-Reply-To
<20220621205201.3162-1-contact+sr.ht@hacktivis.me> (view parent)
DKIM signature
missing
Download raw message
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".
Reply to thread Export thread (mbox)