hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 8a06f9ea51f7d47eefc5947f96d883602a85c7af
parent 9c89abe77111ea94928803c94f59f30fcad9aebd
Author: Byron Torres <b@torresjrjr.com>
Date:   Thu,  8 Jun 2023 13:15:06 +0100

time::date: add %e; update POSIX layout

Diffstat:
Mtime/date/format.ha | 11+++++++----
Mtime/date/parse.ha | 7++++++-
2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/time/date/format.ha b/time/date/format.ha @@ -18,10 +18,8 @@ export def EMAIL: str = "%a, %d %b %Y %H:%M:%S %z"; // zone abbreviation. 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? +// [[format]] layout for the POSIX locale's default date & time representation. +export def POSIX: str = "%a %b %e %H:%M:%S %Y"; // [[format]] layout compatible with RFC 3339. export def RFC3339: str = "%Y-%m-%dT%H:%M:%S%z"; @@ -113,6 +111,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 +179,7 @@ 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), left-padded 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). @@ -252,6 +253,8 @@ export fn format( ("%p", "AM"), // day ("%d", "01"), + // day + ("%e", " 1"), // month ("%m", "01"), // year diff --git a/time/date/parse.ha b/time/date/parse.ha @@ -84,7 +84,7 @@ fn parse_specifier( v.month = scan_for(iter, MONTHS_SHORT...)? + 1; case 'B' => v.month = scan_for(iter, MONTHS...)? + 1; - case 'd' => + case 'd', 'e' => v.day = scan_int(iter, 2)?; case 'F' => v.year = scan_int(iter, 4)?; @@ -350,6 +350,11 @@ fn scan_str(iter: *strings::iterator) (str | failure) = { assert(parse(&v, "%d", "x1") is parsefail , "%d: not parsefail"); let v = newvirtual(); + assert(parse(&v, "%e", " 7") is void , "%d: parsefail"); + assert(v.day is int , "%d: void"); + assert(v.day as int == 7 , "%d: incorrect"); + + let v = newvirtual(); assert(parse(&v, "%F", "2012-10-01") is void , "%d: parsefail"); assert(v.year is int , "%d: void"); assert(v.year as int == 2012 , "%d: incorrect");