hare

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

commit 4cc6365d9adcc291e7352e652e035371cd9b9cec
parent 26db325621d392eda4a4878609735c82949d6d94
Author: Byron Torres <b@torresjrjr.com>
Date:   Thu, 22 Feb 2024 23:44:02 +0000

time::date: rename some calc functions

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

Diffstat:
Mtime/date/daydate.ha | 10+++++-----
Mtime/date/parithm.ha | 8++++----
Mtime/date/reckon.ha | 12++++++------
3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/time/date/daydate.ha b/time/date/daydate.ha @@ -25,16 +25,16 @@ export fn isleapyear(y: int) bool = { // Calculates whether a given year, month, and day-of-month, is a valid date. fn is_valid_ymd(y: int, m: int, d: int) bool = { return m >= 1 && m <= 12 && d >= 1 && - d <= calc_month_daycnt(y, m); + d <= calc_days_in_month(y, m); }; // Calculates whether a given year, and day-of-year, is a valid date. fn is_valid_yd(y: int, yd: int) bool = { - return yd >= 1 && yd <= calc_year_daycnt(y); + return yd >= 1 && yd <= calc_days_in_year(y); }; // Calculates the number of days in the given month of the given year. -fn calc_month_daycnt(y: int, m: int) int = { +fn calc_days_in_month(y: int, m: int) int = { const days_per_month: [_]int = [ 31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]; @@ -46,7 +46,7 @@ fn calc_month_daycnt(y: int, m: int) int = { }; // Calculates the number of days in a given year. -fn calc_year_daycnt(y: int) int = { +fn calc_days_in_year(y: int) int = { return if (isleapyear(y)) 366 else 365; }; @@ -244,7 +244,7 @@ fn calc_daydate__ywd(y: int, w: int, wd: int) (i64 | invalid) = { // Calculates the daydate, // given a year and day-of-year. fn calc_daydate__yd(y: int, yd: int) (i64 | invalid) = { - if (yd < 1 || yd > calc_year_daycnt(y)) { + if (yd < 1 || yd > calc_days_in_year(y)) { return invalid; }; return calc_daydate__ymd(y, 1, 1)? + yd - 1; diff --git a/time/date/parithm.ha b/time/date/parithm.ha @@ -49,21 +49,21 @@ export fn pdiff(a: date, b: date) period = { p.days = _day(&b) - _day(&a); let year = _year(&b); let month = _month(&b); - let daycnt = calc_month_daycnt(year, month); - for (_day(&a) > daycnt || p.days < 0) { + let monthdays = calc_days_in_month(year, month); + for (_day(&a) > monthdays || p.days < 0) { month -= 1; if (month == 0) { year -= 1; month = 12; }; - daycnt = calc_month_daycnt(year, month); + monthdays = calc_days_in_month(year, month); p.months -= 1; if (p.months < 0) { p.years -= 1; p.months += 12; }; - p.days += daycnt; + p.days += monthdays; }; p.hours = _hour(&b) - _hour(&a); diff --git a/time/date/reckon.ha b/time/date/reckon.ha @@ -151,12 +151,12 @@ fn reckon_days(r: *virtual, days: i64, calc: calculus) void = { day += days: int; // day overflow - let month_daycnt = calc_month_daycnt(year, month); - for (day > month_daycnt) { + let monthdays = calc_days_in_month(year, month); + for (day > monthdays) { if (calc & calculus::FLOOR != 0) { day = 1; } else if (calc & calculus::CEIL != 0) { - day = month_daycnt; + day = monthdays; } else if (calc & calculus::HOP != 0) { r.year = year; r.month = month; @@ -174,9 +174,9 @@ fn reckon_days(r: *virtual, days: i64, calc: calculus) void = { year = r.year as int; month = r.month as int; - day -= month_daycnt; + day -= monthdays; }; - month_daycnt = calc_month_daycnt(year, month); + monthdays = calc_days_in_month(year, month); }; for (day < 1) { r.year = year; @@ -186,7 +186,7 @@ fn reckon_days(r: *virtual, days: i64, calc: calculus) void = { year = r.year as int; month = r.month as int; - day += calc_month_daycnt(year, month); + day += calc_days_in_month(year, month); }; r.year = year;