hare

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

commit 500b385c073fb93392224916035262d4c218bac5
parent 24ec13dd2059062f78b7eebb1ff4d35a43ee911a
Author: Byron Torres <b@torresjrjr.com>
Date:   Sat, 11 Jun 2022 03:54:42 +0100

datetime: add sundayweek, rectify 0783e33 ("%U")

The datetime::datetime field `.weeksunday` is renamed to `.sundayweek`.
The function week_starting_sunday() is renamed to sundayweek().
The function _sundayweek() is fixed to use `.sundayweek`.

Cc: Nihal Jere <nihal@nihaljere.xyz>
Fixes: 0783e33 ("datetime: implement %U format specifier and add a test")
Signed-off-by: Byron Torres <b@torresjrjr.com>

Diffstat:
Mdatetime/chronology.ha | 12++++++------
Mdatetime/date.ha | 6+++---
Mdatetime/datetime.ha | 4++--
Mdatetime/format.ha | 2+-
4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/datetime/chronology.ha b/datetime/chronology.ha @@ -34,11 +34,11 @@ export fn yearday(dt: *datetime) int = _yearday(dt); // Returns a [[datetime]]'s ISO week-numbering year. export fn isoweekyear(dt: *datetime) int = _isoweekyear(dt); -// Returns a [[datetime]]'s Gregorian week. +// Returns a [[datetime]]'s Gregorian week starting Monday. export fn week(dt: *datetime) int = _week(dt); // Returns a [[datetime]]'s Gregorian week starting Sunday. -export fn week_starting_sunday(dt: *datetime) int = _week_starting_sunday(dt); +export fn sundayweek(dt: *datetime) int = _sundayweek(dt); // Returns a [[datetime]]'s ISO week. export fn isoweek(dt: *datetime) int = _isoweek(dt); @@ -196,8 +196,8 @@ fn _week(dt: *datetime) int = { }; }; -fn _week_starting_sunday(dt: *datetime) int = { - match (dt.week) { +fn _sundayweek(dt: *datetime) int = { + match (dt.sundayweek) { case void => if (dt.yearday is void) { _yearday(dt); @@ -205,11 +205,11 @@ fn _week_starting_sunday(dt: *datetime) int = { if (dt.weekday is void) { _weekday(dt); }; - dt.weeksunday = calc_week_starting_sunday( + dt.sundayweek = calc_sundayweek( dt.yearday: int, dt.weekday: int, ); - return dt.weeksunday: int; + return dt.sundayweek: int; case let w: int => return w; }; diff --git a/datetime/date.ha b/datetime/date.ha @@ -187,7 +187,7 @@ fn calc_week(yd: int, wd: int) int = { // Calculates the week within a Gregorian year [0..53], // given a day-of-year and day-of-week. // All days in a year before the year's first Sunday belong to week 0. -fn calc_week_starting_sunday(yd: int, wd: int) int = { +fn calc_sundayweek(yd: int, wd: int) int = { return (yd + 6 - (wd % 7)) / 7; }; @@ -541,7 +541,7 @@ fn calc_date_from_yd(y: int, yd: int) (chrono::date | invalid) = { }; }; -@test fn calc_week_starting_sunday() void = { +@test fn calc_sundayweek() void = { const cases = [ ((1, 1), 0), ((1, 2), 0), @@ -563,7 +563,7 @@ fn calc_date_from_yd(y: int, yd: int) (chrono::date | invalid) = { for (let i = 0z; i < len(cases); i += 1) { const params = cases[i].0; const expect = cases[i].1; - const actual = calc_week_starting_sunday(params.0, params.1); + const actual = calc_sundayweek(params.0, params.1); assert(expect == actual, "week miscalculation"); }; }; diff --git a/datetime/datetime.ha b/datetime/datetime.ha @@ -19,7 +19,7 @@ export type datetime = struct { isoweekyear: (void | int), isoweek: (void | int), week: (void | int), - weeksunday: (void | int), + sundayweek: (void | int), weekday: (void | int), hour: (void | int), @@ -42,7 +42,7 @@ fn init() datetime = datetime { isoweekyear = void, isoweek = void, week = void, - weeksunday = void, + sundayweek = void, weekday = void, hour = void, diff --git a/datetime/format.ha b/datetime/format.ha @@ -135,7 +135,7 @@ fn fmtout(out: io::handle, r: rune, dt: *datetime) (size | io::error) = { case 'u' => return fmt::fprint(out, strconv::itos(weekday(dt))); case 'U' => - return fmt::fprintf(out, "{:02}", week_starting_sunday(dt)); + return fmt::fprintf(out, "{:02}", _sundayweek(dt)); case 'w' => return fmt::fprint(out, strconv::itos(weekday(dt) % 7)); case 'W' =>