~sircmpwn/hare-dev

hare: datetime: Add support for parsing timezone offset v1 APPLIED

Haelwenn (lanodan) Monnier: 2
 datetime: Add support for parsing timezone offset
 datetime: Add support for timezone offset

 2 files changed, 37 insertions(+), 4 deletions(-)
#784408 alpine.yml success
#784409 freebsd.yml success
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".
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/hare-dev/patches/33160/mbox | git am -3
Learn more about email & git

[PATCH hare] datetime: Add support for parsing timezone offset Export this patch

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: 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]: mailto: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

[PATCH hare v2] datetime: Add support for timezone offset Export this patch

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
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".