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