hare

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

commit 1dceb79502fafeaeb4cd94dc584884d23ffe50c9
parent b7aeba2e0f10b964a75c6936413ac350e18ac230
Author: Byron Torres <b@torresjrjr.com>
Date:   Tue, 24 May 2022 04:00:20 +0100

time::chrono,datetime: rename epochal to date

"epochal" was awkward. "date", with enough context and documentation,
sounds better and is not that ambiguous with a typical calendar date.

The change in terminology in reflected in the time::chrono and datetime
modules.

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

Diffstat:
Mdatetime/arithmetic.ha | 16++++++++--------
Mdatetime/chronology.ha | 12++++++------
Mdatetime/date.ha | 50+++++++++++++++++++++++++-------------------------
Mdatetime/datetime.ha | 12++++++------
Mtime/chrono/chronology.ha | 18+++++++++---------
5 files changed, 54 insertions(+), 54 deletions(-)

diff --git a/datetime/arithmetic.ha b/datetime/arithmetic.ha @@ -202,8 +202,8 @@ export fn truncate(dt: datetime, u: unit) datetime = { 00, 00, 00, 0, )!; case unit::WEEK => - const epochal = dt.date - (weekday(&dt) - 1); - const ymd = calc_ymd(epochal); + const date = dt.date - (weekday(&dt) - 1); + const ymd = calc_ymd(date); yield new(dt.loc, 0, ymd.0, ymd.1, ymd.2, 00, 00, 00, 0, @@ -322,7 +322,7 @@ export fn add(dt: datetime, flag: calculus, pp: period...) datetime = { for (let i = 0z; i < len(pp); i += 1) { const p = pp[i]; - let latest_epochal = dt.date; + let latest_date = dt.date; if (p.years != 0) { d_year += p.years; @@ -346,14 +346,14 @@ export fn add(dt: datetime, flag: calculus, pp: period...) datetime = { if (p.weeks != 0) { p.days += p.weeks * 7; }; - latest_epochal = calc_epochal_from_ymd( + latest_date = calc_date_from_ymd( d_year, d_month, d_day)!; if (p.days != 0) { - const new_ymd = calc_ymd(latest_epochal + p.days); + const new_ymd = calc_ymd(latest_date + p.days); d_year = new_ymd.0; d_month = new_ymd.1; d_day = new_ymd.2; - latest_epochal = calc_epochal_from_ymd( + latest_date = calc_date_from_ymd( d_year, d_month, d_day)!; }; @@ -387,9 +387,9 @@ export fn add(dt: datetime, flag: calculus, pp: period...) datetime = { }; if (overflowed_days != 0) { - const new_epochal = latest_epochal + + const new_date = latest_date + overflowed_days; - const new_ymd = calc_ymd(new_epochal); + const new_ymd = calc_ymd(new_date); d_year = new_ymd.0; d_month = new_ymd.1; d_day = new_ymd.2; diff --git a/datetime/chronology.ha b/datetime/chronology.ha @@ -11,7 +11,7 @@ use time::chrono; // TODO: Create an exported [[zeroweekday]] field function. // Returns a [[datetime]]'s number of days since the calendar epoch 0000-01-01. -export fn epochal(dt: *datetime) chrono::epochal = _epochal(dt); +export fn epochal(dt: *datetime) chrono::date = _epochal(dt); // Returns a [[datetime]]'s era. export fn era(dt: *datetime) int = _era(dt); @@ -56,7 +56,7 @@ export fn sec(dt: *datetime) int = _sec(dt); export fn nsec(dt: *datetime) int = _nsec(dt); -fn _epochal(dt: *datetime) chrono::epochal = { +fn _epochal(dt: *datetime) chrono::date = { const ldt = transform(*dt, dt.zone.zoffset); return ldt.date - EPOCHAL_GREGORIAN; }; @@ -78,7 +78,7 @@ fn _year(dt: *datetime) int = { const ldt = transform(*dt, dt.zone.zoffset); match (dt.year) { case void => - const ymd = calc_ymd(ldt.date: chrono::epochal); + const ymd = calc_ymd(ldt.date: chrono::date); dt.year = ymd.0; dt.month = ymd.1; dt.day = ymd.2; @@ -92,7 +92,7 @@ fn _month(dt: *datetime) int = { const ldt = transform(*dt, dt.zone.zoffset); match (dt.month) { case void => - const ymd = calc_ymd(ldt.date: chrono::epochal); + const ymd = calc_ymd(ldt.date: chrono::date); dt.year = ymd.0; dt.month = ymd.1; dt.day = ymd.2; @@ -106,7 +106,7 @@ fn _day(dt: *datetime) int = { const ldt = transform(*dt, dt.zone.zoffset); match (dt.day) { case void => - const ymd = calc_ymd(ldt.date: chrono::epochal); + const ymd = calc_ymd(ldt.date: chrono::date); dt.year = ymd.0; dt.month = ymd.1; dt.day = ymd.2; @@ -120,7 +120,7 @@ fn _weekday(dt: *datetime) int = { const ldt = transform(*dt, dt.zone.zoffset); match (dt.weekday) { case void => - dt.weekday = calc_weekday(ldt.date: chrono::epochal); + dt.weekday = calc_weekday(ldt.date: chrono::date); return dt.weekday: int; case let y: int => return y; diff --git a/datetime/date.ha b/datetime/date.ha @@ -68,7 +68,7 @@ fn calc_era(y: int) int = { }; // Calculates the year, month, and day-of-month, given an epochal day. -fn calc_ymd(e: chrono::epochal) (int, int, int) = { +fn calc_ymd(e: chrono::date) (int, int, int) = { // Algorithm adapted from: // https://en.wikipedia.org/wiki/Julian_day#Julian_or_Gregorian_calendar_from_Julian_day_number // @@ -193,7 +193,7 @@ fn calc_week_starting_sunday(yd: int, wd: int) int = { // Calculates the day-of-week, given a epochal day, // from Monday=1 to Sunday=7. -fn calc_weekday(e: chrono::epochal) int = { +fn calc_weekday(e: chrono::date) int = { const wd = ((e + 3) % 7 + 1): int; return if (wd > 0) wd else wd + 7; }; @@ -204,9 +204,9 @@ fn calc_zeroweekday(wd: int) int = { return wd - 1; }; -// Calculates the [[chrono::epochal]], +// Calculates the [[chrono::date]], // given a year, month, and day-of-month. -fn calc_epochal_from_ymd(y: int, m: int, d: int) (chrono::epochal | invalid) = { +fn calc_date_from_ymd(y: int, m: int, d: int) (chrono::date | invalid) = { if (!is_valid_ymd(y, m, d)) { return invalid; }; @@ -225,10 +225,10 @@ fn calc_epochal_from_ymd(y: int, m: int, d: int) (chrono::epochal | invalid) = { return e; }; -// Calculates the [[chrono::epochal]], +// Calculates the [[chrono::date]], // given a year, week, and day-of-week. -fn calc_epochal_from_ywd(y: int, w: int, wd: int) (chrono::epochal | invalid) = { - const jan1 = calc_epochal_from_ymd(y, 1, 1)?; +fn calc_date_from_ywd(y: int, w: int, wd: int) (chrono::date | invalid) = { + const jan1 = calc_date_from_ymd(y, 1, 1)?; const jan1_wd = calc_weekday(jan1); const yd = if (w == 0) { yield wd - jan1_wd + 1; @@ -236,7 +236,7 @@ fn calc_epochal_from_ywd(y: int, w: int, wd: int) (chrono::epochal | invalid) = yield (7 - jan1_wd + 1) + (7 * (w - 1)) + wd; }; const ymd = calc_ymd_from_yd(y, yd)?; - return calc_epochal_from_ymd(ymd.0, ymd.1, ymd.2)?; + return calc_date_from_ymd(ymd.0, ymd.1, ymd.2)?; }; // Calculates a year, month, and day-of-month, @@ -262,14 +262,14 @@ fn calc_ymd_from_yd(y: int, yd: int) ((int, int, int) | invalid) = { return invalid; }; -// Calculates the [[chrono::epochal]], +// Calculates the [[chrono::date]], // given a year and day-of-year. -fn calc_epochal_from_yd(y: int, yd: int) (chrono::epochal | invalid) = { +fn calc_date_from_yd(y: int, yd: int) (chrono::date | invalid) = { const ymd = calc_ymd_from_yd(y, yd)?; - return calc_epochal_from_ymd(ymd.0, ymd.1, ymd.2)?; + return calc_date_from_ymd(ymd.0, ymd.1, ymd.2)?; }; -@test fn calc_epochal_from_ymd() void = { +@test fn calc_date_from_ymd() void = { const cases = [ ((-0768, 02, 05), -999999, false), ((-0001, 12, 31), -719529, false), @@ -305,15 +305,15 @@ fn calc_epochal_from_yd(y: int, yd: int) (chrono::epochal | invalid) = { const params = cases[i].0; const expect = cases[i].1; const should_error = cases[i].2; - const actual = calc_epochal_from_ymd( + const actual = calc_date_from_ymd( params.0, params.1, params.2, ); if (should_error) { assert(actual is invalid, "invalid date accepted"); } else { - assert(actual is chrono::epochal, "valid date not accepted"); - assert(actual as chrono::epochal == expect, "epochal miscalculation"); + assert(actual is chrono::date, "valid date not accepted"); + assert(actual as chrono::date == expect, "date miscalculation"); }; }; }; @@ -364,7 +364,7 @@ fn calc_epochal_from_yd(y: int, yd: int) (chrono::epochal | invalid) = { }; }; -@test fn calc_epochal_from_ywd() void = { +@test fn calc_date_from_ywd() void = { const cases = [ ((-0768, 00, 4), -1000034), ((-0768, 05, 4), -999999), @@ -402,13 +402,13 @@ fn calc_epochal_from_yd(y: int, yd: int) (chrono::epochal | invalid) = { for (let i = 0z; i < len(cases); i += 1) { const ywd = cases[i].0; const expected = cases[i].1; - const actual = calc_epochal_from_ywd(ywd.0, ywd.1, ywd.2)!; + const actual = calc_date_from_ywd(ywd.0, ywd.1, ywd.2)!; assert(actual == expected, - "incorrect calc_epochal_from_ywd() result"); + "incorrect calc_date_from_ywd() result"); }; }; -@test fn calc_epochal_from_yd() void = { +@test fn calc_date_from_yd() void = { const cases = [ (-0768, 36, -999999), (-0001, 365, -719529), @@ -437,14 +437,14 @@ fn calc_epochal_from_yd(y: int, yd: int) (chrono::epochal | invalid) = { const y = cases[i].0; const yd = cases[i].1; const expected = cases[i].2; - const actual = calc_epochal_from_yd(y, yd)!; + const actual = calc_date_from_yd(y, yd)!; assert(expected == actual, - "error in epochal calculation from yd"); + "error in date calculation from yd"); }; - assert(calc_epochal_from_yd(2020, 0) is invalid, - "calc_epochal_from_yd() did not reject invalid yearday"); - assert(calc_epochal_from_yd(2020, 400) is invalid, - "calc_epochal_from_yd() did not reject invalid yearday"); + assert(calc_date_from_yd(2020, 0) is invalid, + "calc_date_from_yd() did not reject invalid yearday"); + assert(calc_date_from_yd(2020, 400) is invalid, + "calc_date_from_yd() did not reject invalid yearday"); }; @test fn calc_ymd() void = { diff --git a/datetime/datetime.ha b/datetime/datetime.ha @@ -116,7 +116,7 @@ export fn new( const nsec = defaults[6]; let m = chrono::moment { - date = calc_epochal_from_ymd(year, month, day)?, + date = calc_date_from_ymd(year, month, day)?, time = calc_time_from_hmsn(hour, min, sec, nsec)?, loc = loc, zone = chrono::zone { ... }, @@ -247,7 +247,7 @@ export fn finish(f: *builder, m: strategy...) (datetime | insufficient | invalid f.month is int && f.day is int ) { - f.date = calc_epochal_from_ymd( + f.date = calc_date_from_ymd( f.year as int, f.month as int, f.day as int, @@ -260,7 +260,7 @@ export fn finish(f: *builder, m: strategy...) (datetime | insufficient | invalid f.year is int && f.yearday is int ) { - f.date = calc_epochal_from_yd( + f.date = calc_date_from_yd( f.year as int, f.yearday as int, )?; @@ -273,7 +273,7 @@ export fn finish(f: *builder, m: strategy...) (datetime | insufficient | invalid f.week is int && f.weekday is int ) { - f.date = calc_epochal_from_ywd( + f.date = calc_date_from_ywd( f.year as int, f.week as int, f.weekday as int, @@ -281,14 +281,14 @@ export fn finish(f: *builder, m: strategy...) (datetime | insufficient | invalid return *f: datetime; }; - // TODO: calendar.ha: calc_epochal_from_isoywd() + // TODO: calendar.ha: calc_date_from_isoywd() }; return insufficient; }; // Specifies which [[builder]] fields and what strategy to use to calculate the -// epochal, and thus a valid [[datetime]]. +// date, and thus a valid [[datetime]]. export type strategy = enum uint { // year, month, day YMD = 1 << 0, diff --git a/time/chrono/chronology.ha b/time/chrono/chronology.ha @@ -9,7 +9,7 @@ export type invalid = !void; export type moment = struct { // The ordinal day (on Earth or otherwise) // since the Hare epoch (zeroth day) 1970-01-01 - date: epochal, + date: date, // The time since the start of the day time: time::duration, @@ -21,22 +21,22 @@ export type moment = struct { zone: zone, }; -// An ordinal day (on Earth or otherwise) since the Hare epoch (zeroth day) -// 1970-01-01. -export type epochal = i64; +// An ordinal day since an epoch. The Hare epoch (zeroth day) 1970 Jan 1st is +// used for terrestrial chronologies. +export type date = i64; // Creates a new [[moment]]. export fn new( loc: locality, - date: epochal, - time: time::duration, + d: date, + t: time::duration, ) (moment | invalid) = { - if (time > loc.daylength) { + if (t > loc.daylength) { return invalid; }; const m = moment { - date = date, - time = time, + date = d, + time = t, loc = loc, zone = zone { ... }, };