commit 6741ce10746c4633ee90dc0b8a05a2e0e07caa8f
parent 67e68fd03cfd7d724c8b04d2d9b5b53ad9ea5e98
Author: Byron Torres <b@torresjrjr.com>
Date: Sat, 23 Apr 2022 13:04:16 +0100
datetime: add %L formatter and STAMP_NOZL layout
Signed-off-by: Byron Torres <b@torresjrjr.com>
Diffstat:
2 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/datetime/format.ha b/datetime/format.ha
@@ -29,6 +29,10 @@ export def STAMP: str = "%Y-%m-%d %H:%M:%S";
// [[datetime::format]] string providing the current timestamp with nanoseconds.
export def STAMP_NANO: str = "%Y-%m-%d %H:%M:%S.%N";
+// [[datetime::format]] string providing the current timestamp with nanoseconds,
+// zone offset, zone abbreviation, and locality.
+export def STAMP_NOZL: str = "%Y-%m-%d %H:%M:%S.%N %z %Z %L";
+
def WEEKDAYS: [_]str = [
"Monday",
"Tuesday",
@@ -108,6 +112,8 @@ fn fmtout(out: io::handle, r: rune, dt: *datetime) (size | io::error) = {
return fmt::fprintf(out, "{:02}", hour12(dt));
case 'j' =>
return fmt::fprint(out, strconv::itos(yearday(dt)));
+ case 'L' =>
+ return fmt::fprint(out, dt.loc.name);
case 'm' =>
return fmt::fprintf(out, "{:02}", month(dt));
case 'M' =>
diff --git a/datetime/parse.ha b/datetime/parse.ha
@@ -80,6 +80,9 @@ export fn parse(build: *builder, layout: str, s: str) (void | invalid) = {
case 'j' =>
build.yearday = clamp_int(
get_max_n_digits(&s_iter, 3)?, 1, 366);
+ case 'L' =>
+ // TODO: Parse %L (locality/timezone name/ID).
+ continue;
case 'm' =>
build.month = clamp_int(
get_max_n_digits(&s_iter, 2)?, 1, 12);