hare

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

commit 0013d3531b87f0a556185ae08e7e52fbc6e7c072
parent 7eba13421f4303c9d0a4398305e0375588ed2c98
Author: Byron Torres <b@torresjrjr.com>
Date:   Thu, 22 Feb 2024 23:44:05 +0000

time::date: change, add layout constants

Rename layout [[EMAILZ]] to [[EMAILZONE]].
Rename layout [[STAMP_NANO]] to [[STAMPNANO]].
Rename layout [[STAMP_ZOFF]] to [[STAMPZOFF]].
Rename layout [[STAMP_ZONE]] to [[STAMPZONE]].
Rename layout [[STAMP_NOZL]] to [[STAMPLOC]].

New layouts with examples:

[[JOURNAL]]
        "2038 Jan 19, Tue 04:14:07 +0100 CET Europe/Amsterdam"
[[WRIST]]
        "Jan-19 Tue 04:14 CET"
[[QUARTZ]]
        "2147480047.012700000"
[[QUARTZZOFF]]
        "2147480047.012700000+0100"
[[QUARTZLOC]]
        "2147480047.012700000:Europe/Amsterdam"

Breaking-Change: 0.24.0
Signed-off-by: Byron Torres <b@torresjrjr.com>

Diffstat:
Mencoding/asn1/+test/decoder_test.ha | 2+-
Mtime/date/date.ha | 4++--
Mtime/date/format.ha | 39++++++++++++++++++++++++++++++---------
3 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/encoding/asn1/+test/decoder_test.ha b/encoding/asn1/+test/decoder_test.ha @@ -289,7 +289,7 @@ fn newdatetime(s: str, tag: utag) []u8 = { let derdatetime = newdatetime("20231030133710.1Z", utag::GENERALIZED_TIME); let dt = read_gtime(&d(derdatetime))!; - assert(date::bsformat(fbuf, date::STAMP_NANO, &dt)! + assert(date::bsformat(fbuf, date::STAMPNANO, &dt)! == "2023-10-30 13:37:10.100000000"); // must end with Z diff --git a/time/date/date.ha b/time/date/date.ha @@ -214,7 +214,7 @@ export fn from_instant(loc: chrono::locality, i: time::instant) date = { // provided, they default to 0. // // let new = date::from_str( -// date::STAMP_NOZL, +// date::STAMPLOC, // "2019-12-27 22:07:08.000000000 +0100 CET Europe/Amsterdam", // locs... // )!; @@ -240,7 +240,7 @@ export fn from_str( @test fn from_str() void = { let testcases: [_](str, str, []chrono::locality, (date | error)) = [ - (STAMP_NOZL, "2001-02-03 15:16:17.123456789 +0000 UTC UTC", [], + (STAMPLOC, "2001-02-03 15:16:17.123456789 +0000 UTC UTC", [], new(chrono::UTC, 0, 2001, 2, 3, 15, 16, 17, 123456789)!), (STAMP, "2001-02-03 15:16:17", [], new(chrono::UTC, 0, 2001, 2, 3, 15, 16, 17)!), diff --git a/time/date/format.ha b/time/date/format.ha @@ -14,7 +14,7 @@ export def EMAIL: str = "%a, %d %b %Y %H:%M:%S %z"; // [[format]] layout for the email date format, with zone offset and // zone abbreviation. -export def EMAILZ: str = "%a, %d %b %Y %H:%M:%S %z %Z"; +export def EMAILZONE: str = "%a, %d %b %Y %H:%M:%S %z %Z"; // [[format]] layout for the POSIX locale's default date & time representation. export def POSIX: str = "%a %b %e %H:%M:%S %Y"; @@ -22,19 +22,40 @@ 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"; -// [[format]] layout for a simple timestamp. +// [[format]] layout for a standard, collatable timestamp. export def STAMP: str = "%Y-%m-%d %H:%M:%S"; -// [[format]] layout for a simple timestamp with nanoseconds. -export def STAMP_NANO: str = "%Y-%m-%d %H:%M:%S.%N"; +// [[format]] layout for a standard, collatable timestamp with nanoseconds. +export def STAMPNANO: str = "%Y-%m-%d %H:%M:%S.%N"; -// [[format]] layout for a simple timestamp with nanoseconds and zone -// offset. -export def STAMP_ZOFF: str = "%Y-%m-%d %H:%M:%S.%N %z"; +// [[format]] layout for a standard, collatable timestamp with nanoseconds +// and zone offset. +export def STAMPZOFF: str = "%Y-%m-%d %H:%M:%S.%N %z"; -// [[format]] layout for a simple timestamp with nanoseconds, +// [[format]] layout for a standard, collatable timestamp with nanoseconds, +// zone offset, and zone abbreviation. +export def STAMPZONE: str = "%Y-%m-%d %H:%M:%S.%N %z %Z"; + +// [[format]] layout for a standard, collatable timestamp with nanoseconds, // zone offset, zone abbreviation, and locality. -export def STAMP_NOZL: str = "%Y-%m-%d %H:%M:%S.%N %z %Z %L"; +export def STAMPLOC: str = "%Y-%m-%d %H:%M:%S.%N %z %Z %L"; + +// [[format]] layout for a friendly, comprehensive, serializable datetime. +export def JOURNAL: str = "%Y %b %d, %a %H:%M:%S %z %Z %L"; + +// [[format]] layout for a friendly, terse, glanceable datetime. +export def WRIST: str = "%b-%d %a %H:%M %Z"; + +// [[format]] layout for a precise timescalar second and nanosecond. +export def QUARTZ: str = "%s.%N"; + +// [[format]] layout for a precise timescalar second, nanosecond, +// and zone offset. +export def QUARTZZOFF: str = "%s.%N%z"; + +// [[format]] layout for a precise timescalar second, nanosecond, +// and locality. +export def QUARTZLOC: str = "%s.%N:%L"; def WEEKDAYS: [_]str = [ "Monday",