~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
5 3

[PATCH hare 1/2] time::date: implement %e

Details
Message ID
<20230604014414.21798-1-sebastian@sebsite.pw>
DKIM signature
missing
Download raw message
Patch: +7 -4
So the POSIX layout format is now actually correct

Signed-off-by: Sebastian <sebastian@sebsite.pw>
---
 time/date/format.ha | 9 ++++++---
 time/date/parse.ha  | 2 +-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/time/date/format.ha b/time/date/format.ha
index de95565c..96941451 100644
--- a/time/date/format.ha
+++ b/time/date/format.ha
@@ -19,9 +19,8 @@ export def EMAIL: str = "%a, %d %b %Y %H:%M:%S %z";
export def EMAILZ: str = "%a, %d %b %Y %H:%M:%S %z %Z";

// [[format]] layout partly compatible with the default layout format
// for the POSIX locale. %d is used in place of POSIX %e.
export def POSIX: str = "%a %b %d %H:%M:%S %Z %Y";
// TODO: Actually implement '%e' and thus the POSIX layout format?
// for the POSIX locale.
export def POSIX: str = "%a %b %e %H:%M:%S %Z %Y";

// [[format]] layout compatible with RFC 3339.
export def RFC3339: str = "%Y-%m-%dT%H:%M:%S%z";
@@ -113,6 +112,8 @@ fn fmtout(out: io::handle, r: rune, d: *date) (size | io::error) = {
		return fmt::fprint(out, MONTHS[_month(d) - 1]);
	case 'd' =>
		return fmt::fprintf(out, "{:02}", _day(d));
	case 'e' =>
		return fmt::fprintf(out, "{: 2}", _day(d));
	case 'F' =>
		return fmt::fprintf(out, "{:04}-{:02}-{:02}", _year(d), _month(d), _day(d));
	case 'H' =>
@@ -179,6 +180,8 @@ fn fmtout(out: io::handle, r: rune, d: *date) (size | io::error) = {
// 	%b -- The abbreviated name of the month.
// 	%B -- The full name of the month.
// 	%d -- The day of the month (decimal, range 01 to 31).
// 	%e -- The day of the month (decimal, range  1 to 31), but a leading zero
// 	      is replaced with a space.
// 	%F -- The full date, equivalent to %Y-%m-%d
// 	%H -- The hour of the day as from a 24-hour clock (range 00 to 23).
// 	%I -- The hour of the day as from a 12-hour clock (range 01 to 12).
diff --git a/time/date/parse.ha b/time/date/parse.ha
index 1c5b076f..3ff4b772 100644
--- a/time/date/parse.ha
+++ b/time/date/parse.ha
@@ -84,7 +84,7 @@ fn parse_specifier(
		scan_for(iter, MONTHS_SHORT...)? + 1;
	case 'B' => v.month =
		scan_for(iter, MONTHS...)? + 1;
	case 'd' => v.day =
	case 'd', 'e' => v.day =
		scan_int(iter, 2, false)?;
	case 'F' =>
		v.year = scan_int(iter, 4, false)?;
-- 
2.40.1

[PATCH hare 2/2] time::date: remove pad param from scan_int

Details
Message ID
<20230604014414.21798-2-sebastian@sebsite.pw>
In-Reply-To
<20230604014414.21798-1-sebastian@sebsite.pw> (view parent)
DKIM signature
missing
Download raw message
Patch: +22 -23
This didn't have any effect.

Signed-off-by: Sebastian <sebastian@sebsite.pw>
---
 time/date/parse.ha | 45 ++++++++++++++++++++++-----------------------
 1 file changed, 22 insertions(+), 23 deletions(-)

diff --git a/time/date/parse.ha b/time/date/parse.ha
index 3ff4b772..53744b55 100644
--- a/time/date/parse.ha
+++ b/time/date/parse.ha
@@ -85,47 +85,47 @@ fn parse_specifier(
	case 'B' => v.month =
		scan_for(iter, MONTHS...)? + 1;
	case 'd', 'e' => v.day =
		scan_int(iter, 2, false)?;
		scan_int(iter, 2)?;
	case 'F' =>
		v.year = scan_int(iter, 4, false)?;
		v.year = scan_int(iter, 4)?;
		eat_rune(iter, '-')?;
		v.month = scan_int(iter, 2, false)?;
		v.month = scan_int(iter, 2)?;
		eat_rune(iter, '-')?;
		v.day = scan_int(iter, 2, false)?;
		v.day = scan_int(iter, 2)?;
	case 'H' => v.hour =
		scan_int(iter, 2, false)?;
		scan_int(iter, 2)?;
	case 'I' => v.halfhour =
		scan_int(iter, 2, false)?;
		scan_int(iter, 2)?;
	case 'j' => v.yearday =
		scan_int(iter, 3, false)?;
		scan_int(iter, 3)?;
	case 'L' => v.locname =
		scan_str(iter)?;
	case 'm' => v.month =
		scan_int(iter, 2, false)?;
		scan_int(iter, 2)?;
	case 'M' => v.minute =
		scan_int(iter, 2, false)?;
		scan_int(iter, 2)?;
	case 'N' => v.nanosecond =
		scan_int(iter, 9, true)?;
		scan_int(iter, 9)?;
	case 'p' => v.ampm = // AM=false PM=true
		scan_for(iter, "AM", "PM", "am", "pm")? % 2 == 1;
	case 'S' => v.second =
		scan_int(iter, 2, false)?;
		scan_int(iter, 2)?;
	case 'T' =>
		v.hour = scan_int(iter, 2, false)?;
		v.hour = scan_int(iter, 2)?;
		eat_rune(iter, ':')?;
		v.minute = scan_int(iter, 2, false)?;
		v.minute = scan_int(iter, 2)?;
		eat_rune(iter, ':')?;
		v.second = scan_int(iter, 2, false)?;
		v.second = scan_int(iter, 2)?;
	case 'u' => v.weekday =
		scan_int(iter, 1, false)? - 1;
		scan_int(iter, 1)? - 1;
	case 'U' => v.week =
		scan_int(iter, 2, false)?;
		scan_int(iter, 2)?;
	case 'w' => v.weekday =
		scan_int(iter, 1, false)? - 1;
		scan_int(iter, 1)? - 1;
	case 'W' => v.week =
		scan_int(iter, 2, false)?;
		scan_int(iter, 2)?;
	case 'Y' => v.year =
		scan_int(iter, 4, false)?;
		scan_int(iter, 4)?;
	case 'z' => v.zoff =
		scan_zo(iter)?;
	case 'Z' => v.zabbr =
@@ -173,8 +173,7 @@ fn scan_for(iter: *strings::iterator, list: str...) (int | failure) = {

// Scans the iterator upto n consecutive numeric digits.
// Returns the resulting int.
// If pad is true, the number is right-padded with zeroes upto n digits.
fn scan_int(iter: *strings::iterator, n: size, pad: bool) (int | failure) = {
fn scan_int(iter: *strings::iterator, n: size) (int | failure) = {
	let copy = *iter;
	for (let i = 0z; i < n; i += 1) {
		let rn: rune = match (strings::next(iter)) {
@@ -219,7 +218,7 @@ fn scan_zo(iter: *strings::iterator) (time::duration | failure) = {
	if (r == 'Z' || r == 'z') {
		return 0;
	};
	let zo = scan_int(iter, 2, false)? * time::HOUR;
	let zo = scan_int(iter, 2)? * time::HOUR;
	match (strings::next(iter)) {
	case void => void;
	case let r: rune =>
@@ -227,7 +226,7 @@ fn scan_zo(iter: *strings::iterator) (time::duration | failure) = {
			strings::next(iter);
		};
	};
	zo += scan_int(iter, 2, false)? * time::MINUTE;
	zo += scan_int(iter, 2)? * time::MINUTE;
	if (r == '-') {
		zo *= -1;
	};
-- 
2.40.1

[hare/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CT3HJ2V50QI3.1K2UNS94HZS5Z@cirno2>
In-Reply-To
<20230604014414.21798-2-sebastian@sebsite.pw> (view parent)
DKIM signature
missing
Download raw message
hare/patches: SUCCESS in 1m43s

[time::date: implement %e][0] from [Sebastian][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/41625
[1]: sebastian@sebsite.pw

✓ #1001161 SUCCESS hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/1001161
✓ #1001160 SUCCESS hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/1001160

Re: [PATCH hare 2/2] time::date: remove pad param from scan_int

Details
Message ID
<CT5X1TX1N3YZ.2E27WLHV1FSF5@cabin>
In-Reply-To
<20230604014414.21798-2-sebastian@sebsite.pw> (view parent)
DKIM signature
missing
Download raw message
On Sun Jun 4, 2023 at 1:44 AM UTC, Sebastian wrote:
> This didn't have any effect.
-%<-
>  	case 'N' => v.nanosecond =
> -		scan_int(iter, 9, true)?;
> +		scan_int(iter, 9)?;

It does have an effect here. `true` is given here, because nanoseconds
are always right-padded with at least 9 (sometimes imaginary) zeros.
Otherwise, the ".123" would set .nsec to 000000123, not 123000000.

I could have and probably should have written a separate function called
scan_padded_int(). You can send a patch for that. Don't send it with the
%e patch, because I'm still reviewing it.

Re: [PATCH hare 2/2] time::date: remove pad param from scan_int

Details
Message ID
<CT6A4FNRKPE5.2L5SCAC19Q7Z5@notmylaptop>
In-Reply-To
<CT5X1TX1N3YZ.2E27WLHV1FSF5@cabin> (view parent)
DKIM signature
missing
Download raw message
On Tue Jun 6, 2023 at 6:21 PM EDT, Byron Torres wrote:
> On Sun Jun 4, 2023 at 1:44 AM UTC, Sebastian wrote:
> > This didn't have any effect.
> -%<-
> >  	case 'N' => v.nanosecond =
> > -		scan_int(iter, 9, true)?;
> > +		scan_int(iter, 9)?;
>
> It does have an effect here. `true` is given here, because nanoseconds
> are always right-padded with at least 9 (sometimes imaginary) zeros.
> Otherwise, the ".123" would set .nsec to 000000123, not 123000000.

Currently the scan_int function currently doesn't do anything with the
'pad' parameter, which is why I thought it could be removed. I take it
this is a bug then?

Re: [PATCH hare 2/2] time::date: remove pad param from scan_int

Details
Message ID
<CT6I9U04DEFD.16ZYHWBB7QAQP@cabin>
In-Reply-To
<CT6A4FNRKPE5.2L5SCAC19Q7Z5@notmylaptop> (view parent)
DKIM signature
missing
Download raw message
On Wed Jun 7, 2023 at 8:35 AM UTC, Sebastian wrote:
> On Tue Jun 6, 2023 at 6:21 PM EDT, Byron Torres wrote:
> > On Sun Jun 4, 2023 at 1:44 AM UTC, Sebastian wrote:
> > > This didn't have any effect.
> > -%<-
> > >  	case 'N' => v.nanosecond =
> > > -		scan_int(iter, 9, true)?;
> > > +		scan_int(iter, 9)?;
> >
> > It does have an effect here. `true` is given here, because nanoseconds
> > are always right-padded with at least 9 (sometimes imaginary) zeros.
> > Otherwise, the ".123" would set .nsec to 000000123, not 123000000.
>
> Currently the scan_int function currently doesn't do anything with the
> 'pad' parameter, which is why I thought it could be removed. I take it
> this is a bug then?

Seems like bgs's 11db66bdb commit had changed scan_int(), without
accounting for the `pad` parameter, making it as if `pad` was always
true. The test suite didn't catch this.

I'm gonna refactor this.
Reply to thread Export thread (mbox)