hare

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

commit 8283ddfb77f5e894fdacc091e46fc4d4fdeb1284
parent 6dd66f750cbdc277accbfe99d8af4a0514796a3d
Author: Byron Torres <b@torresjrjr.com>
Date:   Sat, 13 May 2023 19:38:03 +0100

time: improve function parameter names

Some time::duration parameters are named 'x' to disambiguate from 'd'
for "dates". 'dt' (datetime) paramters are renamed to 'd'.

Diffstat:
Mtime/arithm.ha | 30+++++++++++++++---------------
Mtime/chrono/arithmetic.ha | 4++--
Mtime/chrono/chronology.ha | 6+++---
Mtime/conv.ha | 2+-
Mtime/date/arithmetic.ha | 88++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mtime/date/chronology.ha | 272++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mtime/date/datetime.ha | 72++++++++++++++++++++++++++++++++++++------------------------------------
Mtime/date/duration.ha | 4++--
Mtime/date/format.ha | 74+++++++++++++++++++++++++++++++++++++-------------------------------------
Mtime/date/reckon.ha | 20++++++++++----------
Mtime/date/timezone.ha | 4++--
Mtime/date/virtual.ha | 8++++----
12 files changed, 292 insertions(+), 292 deletions(-)

diff --git a/time/arithm.ha b/time/arithm.ha @@ -6,18 +6,18 @@ use math; // Adds a [[duration]] to an [[instant]], returning an instant further in the // future (given a positive duration), or further in the past (given a negative // duration). -export fn add(a: instant, d: duration) instant = { - if (d == 0) { - return a; - } else if (d > 0) { +export fn add(i: instant, x: duration) instant = { + if (x == 0) { + return i; + } else if (x > 0) { return instant { - sec = a.sec + (a.nsec + d) / SECOND, - nsec = (a.nsec + d) % SECOND, + sec = i.sec + (i.nsec + x) / SECOND, + nsec = (i.nsec + x) % SECOND, }; } else { return instant { - sec = a.sec + (a.nsec + d - SECOND + NANOSECOND) / SECOND, - nsec = (a.nsec + (d % SECOND) + SECOND) % SECOND, + sec = i.sec + (i.nsec + x - SECOND + NANOSECOND) / SECOND, + nsec = (i.nsec + (x % SECOND) + SECOND) % SECOND, }; }; }; @@ -39,12 +39,12 @@ export fn compare(a: instant, b: instant) i8 = { // Scales the given [[instant]]'s scalar value by a factor 'f'. Make sure to // know what epoch you're dealing with. -export fn mult(a: instant, f: f64) instant = { +export fn mult(i: instant, f: f64) instant = { // use positive numbers for convenience - const positive = if (a.sec < 0 ^^ f < 0.0) false else true; + const positive = if (i.sec < 0 ^^ f < 0.0) false else true; const f = if (f < 0.0) -f else f; - const asec: i64 = if (a.sec < 0) -a.sec - 1 else a.sec; - const ansec: i64 = if (a.sec < 0) SECOND - a.nsec else a.nsec; + const asec: i64 = if (i.sec < 0) -i.sec - 1 else i.sec; + const ansec: i64 = if (i.sec < 0) SECOND - i.nsec else i.nsec; // initial multiply const fsec = (asec: f64 * f); @@ -79,7 +79,7 @@ export fn mult(a: instant, f: f64) instant = { @test fn add() void = { const cases = [ - // instant a duration d instant b + // instant a duration x instant b ( 0, 0, -2000000001, -3, 999999999), ( 0, 0, -2000000000, -2, 0), ( 0, 0, -1999999999, -2, 1), @@ -148,9 +148,9 @@ export fn mult(a: instant, f: f64) instant = { for (let i = 0z; i < len(cases); i += 1) { const C = cases[i]; const a = instant { sec = C.0, nsec = C.1 }; - const d = C.2; + const x = C.2; const b = instant { sec = C.3, nsec = C.4 }; - const B = add(a, d); + const B = add(a, x); assert(B.sec == b.sec, "time::add() .sec error"); assert(B.nsec == b.nsec, "time::add() .nsec error"); }; diff --git a/time/chrono/arithmetic.ha b/time/chrono/arithmetic.ha @@ -45,8 +45,8 @@ export fn diff(a: *moment, b: *moment) (time::duration | discontinuity) = { }; // Adds a [[time::duration]] to a [[moment]] with [[time::add]]. -export fn add(m: *moment, d: time::duration) moment = { - return new(m.loc, time::add(*(m: *time::instant), d)); +export fn add(m: *moment, x: time::duration) moment = { + return new(m.loc, time::add(*(m: *time::instant), x)); }; fn convertpair( diff --git a/time/chrono/chronology.ha b/time/chrono/chronology.ha @@ -39,10 +39,10 @@ export type moment = struct { // Creates a new [[moment]]. Uses a given [[time::instant]] with a [[timescale]] // associated with a given [[locality]]. -export fn new(loc: locality, inst: time::instant) moment = { +export fn new(loc: locality, i: time::instant) moment = { return moment { - sec = inst.sec, - nsec = inst.nsec, + sec = i.sec, + nsec = i.nsec, loc = loc, zone = null, date = void, diff --git a/time/conv.ha b/time/conv.ha @@ -1,6 +1,6 @@ // Converts a given [[instant]] to a Unix timestamp. // Note, nanosecond information is lost during conversion. -export fn unix(a: instant) i64 = a.sec; +export fn unix(i: instant) i64 = i.sec; // Converts a given Unix timestamp to an [[instant]]. export fn from_unix(u: i64) instant = instant { diff --git a/time/date/arithmetic.ha b/time/date/arithmetic.ha @@ -123,7 +123,7 @@ export fn unitdiff(a: date, b: date, u: unit) i64 = { // // For example, truncating to the nearest unit::MONTH will set the 'day', // 'hour', 'minute', 'second', and 'nanosecond' fields to their minimum values. -export fn truncate(dt: date, u: unit) date = { +export fn truncate(d: date, u: unit) date = { // TODO: There exist timezones where midnight is invalid on certain // days. The new()! calls will fail, but we probably don't want to '?' // propagate [[invalid]] to keep this function's use simple. The minimum @@ -132,49 +132,49 @@ export fn truncate(dt: date, u: unit) date = { // realize(), and then use realize() here. return switch (u) { case unit::ERA => - yield new(dt.loc, chrono::mzone(&dt).zoff, + yield new(d.loc, chrono::mzone(&d).zoff, 1, 1, 1, 0, 0, 0, 0, )!; case unit::YEAR => - yield new(dt.loc, chrono::mzone(&dt).zoff, - _year(&dt), 1, 1, + yield new(d.loc, chrono::mzone(&d).zoff, + _year(&d), 1, 1, 0, 0, 0, 0, )!; case unit::MONTH => - yield new(dt.loc, chrono::mzone(&dt).zoff, - _year(&dt), _month(&dt), 1, + yield new(d.loc, chrono::mzone(&d).zoff, + _year(&d), _month(&d), 1, 0, 0, 0, 0, )!; case unit::WEEK => - const date = chrono::date(&dt) - _weekday(&dt); + const date = chrono::date(&d) - _weekday(&d); const ymd = calc_ymd(date); - yield new(dt.loc, chrono::mzone(&dt).zoff, + yield new(d.loc, chrono::mzone(&d).zoff, ymd.0, ymd.1, ymd.2, 0, 0, 0, 0, )!; case unit::DAY => - yield new(dt.loc, chrono::mzone(&dt).zoff, - _year(&dt), _month(&dt), _day(&dt), + yield new(d.loc, chrono::mzone(&d).zoff, + _year(&d), _month(&d), _day(&d), 0, 0, 0, 0, )!; case unit::HOUR => - yield new(dt.loc, chrono::mzone(&dt).zoff, - _year(&dt), _month(&dt), _day(&dt), - _hour(&dt), 0, 0, 0, + yield new(d.loc, chrono::mzone(&d).zoff, + _year(&d), _month(&d), _day(&d), + _hour(&d), 0, 0, 0, )!; case unit::MINUTE => - yield new(dt.loc, chrono::mzone(&dt).zoff, - _year(&dt), _month(&dt), _day(&dt), - _hour(&dt), _minute(&dt), 0, 0, + yield new(d.loc, chrono::mzone(&d).zoff, + _year(&d), _month(&d), _day(&d), + _hour(&d), _minute(&d), 0, 0, )!; case unit::SECOND => - yield new(dt.loc, chrono::mzone(&dt).zoff, - _year(&dt), _month(&dt), _day(&dt), - _hour(&dt), _minute(&dt), _second(&dt), 0, + yield new(d.loc, chrono::mzone(&d).zoff, + _year(&d), _month(&d), _day(&d), + _hour(&d), _minute(&d), _second(&d), 0, )!; case unit::NANOSECOND => - yield dt; + yield d; }; }; @@ -286,10 +286,10 @@ export fn truncate(dt: date, u: unit) date = { ), ]; for (let i = 0z; i < len(cases); i += 1) { - const dta = cases[i].0; - const dtb = cases[i].1; + const da = cases[i].0; + const db = cases[i].1; const expected = cases[i].2; - const actual = pdiff(dta, dtb); + const actual = pdiff(da, db); assert(peq(actual, expected), "pdiff miscalculation"); }; }; @@ -324,73 +324,73 @@ export fn truncate(dt: date, u: unit) date = { ), ]; for (let i = 0z; i < len(cases); i += 1) { - const dta = cases[i].0; - const dtb = cases[i].1; + const da = cases[i].0; + const db = cases[i].1; const expected = cases[i].2; - assert(unitdiff(dta, dtb, unit::YEAR) == expected.0, + assert(unitdiff(da, db, unit::YEAR) == expected.0, "invalid diff_in_years() result"); - assert(unitdiff(dta, dtb, unit::MONTH) == expected.1, + assert(unitdiff(da, db, unit::MONTH) == expected.1, "invalid diff_in_months() result"); - assert(unitdiff(dta, dtb, unit::WEEK) == expected.2, + assert(unitdiff(da, db, unit::WEEK) == expected.2, "invalid diff_in_weeks() result"); - assert(unitdiff(dta, dtb, unit::DAY) == expected.3, + assert(unitdiff(da, db, unit::DAY) == expected.3, "invalid diff_in_days() result"); - assert(unitdiff(dta, dtb, unit::HOUR) == expected.4, + assert(unitdiff(da, db, unit::HOUR) == expected.4, "invalid diff_in_hours() result"); - assert(unitdiff(dta, dtb, unit::MINUTE) == expected.5, + assert(unitdiff(da, db, unit::MINUTE) == expected.5, "invalid diff_in_minutes() result"); - assert(unitdiff(dta, dtb, unit::SECOND) == expected.6, + assert(unitdiff(da, db, unit::SECOND) == expected.6, "invalid diff_in_seconds() result"); - assert(unitdiff(dta, dtb, unit::NANOSECOND) == expected.7, + assert(unitdiff(da, db, unit::NANOSECOND) == expected.7, "invalid diff_in_nanoseconds() result"); }; }; @test fn truncate() void = { - const dt = new(chrono::UTC, 0, 1994, 8, 27, 11, 20, 1, 2)!; + const d = new(chrono::UTC, 0, 1994, 8, 27, 11, 20, 1, 2)!; assert(chrono::eq( - &truncate(dt, unit::ERA), + &truncate(d, unit::ERA), &new(chrono::UTC, 0, 1, 1, 1, 0, 0, 0, 0)!)!, "invalid truncate() result 01"); assert(chrono::eq( - &truncate(dt, unit::YEAR), + &truncate(d, unit::YEAR), &new(chrono::UTC, 0, 1994, 1, 1, 0, 0, 0, 0)!)!, "invalid truncate() result 02"); assert(chrono::eq( - &truncate(dt, unit::MONTH), + &truncate(d, unit::MONTH), &new(chrono::UTC, 0, 1994, 8, 1, 0, 0, 0, 0)!)!, "invalid truncate() result 03"); assert(chrono::eq( - &truncate(dt, unit::WEEK), + &truncate(d, unit::WEEK), &new(chrono::UTC, 0, 1994, 8, 22, 0, 0, 0, 0)!)!, "invalid truncate() result 04"); assert(chrono::eq( - &truncate(dt, unit::DAY), + &truncate(d, unit::DAY), &new(chrono::UTC, 0, 1994, 8, 27, 0, 0, 0, 0)!)!, "invalid truncate() result 05"); assert(chrono::eq( - &truncate(dt, unit::HOUR), + &truncate(d, unit::HOUR), &new(chrono::UTC, 0, 1994, 8, 27, 11, 0, 0, 0)!)!, "invalid truncate() result 06"); assert(chrono::eq( - &truncate(dt, unit::MINUTE), + &truncate(d, unit::MINUTE), &new(chrono::UTC, 0, 1994, 8, 27, 11, 20, 0, 0)!)!, "invalid truncate() result 07"); assert(chrono::eq( - &truncate(dt, unit::SECOND), + &truncate(d, unit::SECOND), &new(chrono::UTC, 0, 1994, 8, 27, 11, 20, 1, 0)!)!, "invalid truncate() result 08"); assert(chrono::eq( - &truncate(dt, unit::NANOSECOND), - &dt)!, + &truncate(d, unit::NANOSECOND), + &d)!, "invalid truncate() result 09"); }; diff --git a/time/date/chronology.ha b/time/date/chronology.ha @@ -8,267 +8,267 @@ use time::chrono; // parameters of the [[new]] function. // Returns a [[date]]'s era. -export fn era(dt: *date) int = _era(dt); +export fn era(d: *date) int = _era(d); // Returns a [[date]]'s year. -export fn year(dt: *date) int = _year(dt); +export fn year(d: *date) int = _year(d); // Returns a [[date]]'s month of the year. -export fn month(dt: *date) int = _month(dt); +export fn month(d: *date) int = _month(d); // Returns a [[date]]'s day of the month. -export fn day(dt: *date) int = _day(dt); +export fn day(d: *date) int = _day(d); // Returns a [[date]]'s day of the week; Monday=0 to Sunday=6. -export fn weekday(dt: *date) int = _weekday(dt); +export fn weekday(d: *date) int = _weekday(d); // Returns a [[date]]'s ordinal day of the year. -export fn yearday(dt: *date) int = _yearday(dt); +export fn yearday(d: *date) int = _yearday(d); // Returns a [[date]]'s ISO week-numbering year. -export fn isoweekyear(dt: *date) int = _isoweekyear(dt); +export fn isoweekyear(d: *date) int = _isoweekyear(d); // Returns a [[date]]'s Gregorian week starting Monday. -export fn week(dt: *date) int = _week(dt); +export fn week(d: *date) int = _week(d); // Returns a [[date]]'s Gregorian week starting Sunday. -export fn sundayweek(dt: *date) int = _sundayweek(dt); +export fn sundayweek(d: *date) int = _sundayweek(d); // Returns a [[date]]'s ISO week. -export fn isoweek(dt: *date) int = _isoweek(dt); +export fn isoweek(d: *date) int = _isoweek(d); // Returns a [[date]]'s hour of the day. -export fn hour(dt: *date) int = _hour(dt); +export fn hour(d: *date) int = _hour(d); // Returns a [[date]]'s minute of the hour. -export fn minute(dt: *date) int = _minute(dt); +export fn minute(d: *date) int = _minute(d); // Returns a [[date]]'s second of the minute. -export fn second(dt: *date) int = _second(dt); +export fn second(d: *date) int = _second(d); // Returns a [[date]]'s nanosecond of the second. -export fn nanosecond(dt: *date) int = _nanosecond(dt); +export fn nanosecond(d: *date) int = _nanosecond(d); -fn _era(dt: *date) int = { - match (dt.era) { +fn _era(d: *date) int = { + match (d.era) { case void => - if (dt.year is void) { - dt.year = _year(dt); + if (d.year is void) { + d.year = _year(d); }; - dt.era = calc_era(dt.year: int); - return dt.era: int; + d.era = calc_era(d.year: int); + return d.era: int; case let a: int => return a; }; }; -fn _year(dt: *date) int = { - match (dt.year) { +fn _year(d: *date) int = { + match (d.year) { case void => - const ymd = calc_ymd(chrono::date(dt)); - dt.year = ymd.0; - dt.month = ymd.1; - dt.day = ymd.2; - return dt.year: int; + const ymd = calc_ymd(chrono::date(d)); + d.year = ymd.0; + d.month = ymd.1; + d.day = ymd.2; + return d.year: int; case let y: int => return y; }; }; -fn _month(dt: *date) int = { - match (dt.month) { +fn _month(d: *date) int = { + match (d.month) { case void => - const ymd = calc_ymd(chrono::date(dt)); - dt.year = ymd.0; - dt.month = ymd.1; - dt.day = ymd.2; - return dt.month: int; + const ymd = calc_ymd(chrono::date(d)); + d.year = ymd.0; + d.month = ymd.1; + d.day = ymd.2; + return d.month: int; case let y: int => return y; }; }; -fn _day(dt: *date) int = { - match (dt.day) { +fn _day(d: *date) int = { + match (d.day) { case void => - const ymd = calc_ymd(chrono::date(dt)); - dt.year = ymd.0; - dt.month = ymd.1; - dt.day = ymd.2; - return dt.day: int; + const ymd = calc_ymd(chrono::date(d)); + d.year = ymd.0; + d.month = ymd.1; + d.day = ymd.2; + return d.day: int; case let y: int => return y; }; }; -fn _weekday(dt: *date) int = { - match (dt.weekday) { +fn _weekday(d: *date) int = { + match (d.weekday) { case void => - dt.weekday = calc_weekday(chrono::date(dt)); - return dt.weekday: int; + d.weekday = calc_weekday(chrono::date(d)); + return d.weekday: int; case let y: int => return y; }; }; -fn _yearday(dt: *date) int = { - match (dt.yearday) { +fn _yearday(d: *date) int = { + match (d.yearday) { case void => - if (dt.year is void) { - _year(dt); + if (d.year is void) { + _year(d); }; - if (dt.month is void) { - _month(dt); + if (d.month is void) { + _month(d); }; - if (dt.day is void) { - _day(dt); + if (d.day is void) { + _day(d); }; - dt.yearday = calc_yearday( - dt.year: int, - dt.month: int, - dt.day: int, + d.yearday = calc_yearday( + d.year: int, + d.month: int, + d.day: int, ); - return dt.yearday: int; + return d.yearday: int; case let yd: int => return yd; }; }; -fn _isoweekyear(dt: *date) int = { - match (dt.isoweekyear) { +fn _isoweekyear(d: *date) int = { + match (d.isoweekyear) { case void => - if (dt.year is void) { - _year(dt); + if (d.year is void) { + _year(d); }; - if (dt.month is void) { - _month(dt); + if (d.month is void) { + _month(d); }; - if (dt.day is void) { - _day(dt); + if (d.day is void) { + _day(d); }; - if (dt.weekday is void) { - _weekday(dt); + if (d.weekday is void) { + _weekday(d); }; - dt.isoweekyear = calc_isoweekyear( - dt.year: int, - dt.month: int, - dt.day: int, - dt.weekday: int, + d.isoweekyear = calc_isoweekyear( + d.year: int, + d.month: int, + d.day: int, + d.weekday: int, ); - return dt.isoweekyear: int; + return d.isoweekyear: int; case let iwy: int => return iwy; }; }; -fn _week(dt: *date) int = { - match (dt.week) { +fn _week(d: *date) int = { + match (d.week) { case void => - if (dt.yearday is void) { - _yearday(dt); + if (d.yearday is void) { + _yearday(d); }; - if (dt.weekday is void) { - _weekday(dt); + if (d.weekday is void) { + _weekday(d); }; - dt.week = calc_week( - dt.yearday: int, - dt.weekday: int, + d.week = calc_week( + d.yearday: int, + d.weekday: int, ); - return dt.week: int; + return d.week: int; case let w: int => return w; }; }; -fn _sundayweek(dt: *date) int = { - match (dt.sundayweek) { +fn _sundayweek(d: *date) int = { + match (d.sundayweek) { case void => - if (dt.yearday is void) { - _yearday(dt); + if (d.yearday is void) { + _yearday(d); }; - if (dt.weekday is void) { - _weekday(dt); + if (d.weekday is void) { + _weekday(d); }; - dt.sundayweek = calc_sundayweek( - dt.yearday: int, - dt.weekday: int, + d.sundayweek = calc_sundayweek( + d.yearday: int, + d.weekday: int, ); - return dt.sundayweek: int; + return d.sundayweek: int; case let w: int => return w; }; }; -fn _isoweek(dt: *date) int = { - match (dt.isoweek) { +fn _isoweek(d: *date) int = { + match (d.isoweek) { case void => - if (dt.year is void) { - _year(dt); + if (d.year is void) { + _year(d); }; - if (dt.week is void) { - _week(dt); + if (d.week is void) { + _week(d); }; - dt.isoweek = calc_isoweek( - dt.year: int, - dt.week: int, + d.isoweek = calc_isoweek( + d.year: int, + d.week: int, ); - return dt.isoweek: int; + return d.isoweek: int; case let iw: int => return iw; }; }; -fn _hour(dt: *date) int = { - match (dt.hour) { +fn _hour(d: *date) int = { + match (d.hour) { case void => - const hmsn = calc_hmsn(chrono::time(dt)); - dt.hour = hmsn.0; - dt.minute = hmsn.1; - dt.second = hmsn.2; - dt.nanosecond = hmsn.3; - return dt.hour: int; + const hmsn = calc_hmsn(chrono::time(d)); + d.hour = hmsn.0; + d.minute = hmsn.1; + d.second = hmsn.2; + d.nanosecond = hmsn.3; + return d.hour: int; case let h: int => return h; }; }; -fn _minute(dt: *date) int = { - match (dt.minute) { +fn _minute(d: *date) int = { + match (d.minute) { case void => - const hmsn = calc_hmsn(chrono::time(dt)); - dt.hour = hmsn.0; - dt.minute = hmsn.1; - dt.second = hmsn.2; - dt.nanosecond = hmsn.3; - return dt.minute: int; + const hmsn = calc_hmsn(chrono::time(d)); + d.hour = hmsn.0; + d.minute = hmsn.1; + d.second = hmsn.2; + d.nanosecond = hmsn.3; + return d.minute: int; case let m: int => return m; }; }; -fn _second(dt: *date) int = { - match (dt.second) { +fn _second(d: *date) int = { + match (d.second) { case void => - const hmsn = calc_hmsn(chrono::time(dt)); - dt.hour = hmsn.0; - dt.minute = hmsn.1; - dt.second = hmsn.2; - dt.nanosecond = hmsn.3; - return dt.second: int; + const hmsn = calc_hmsn(chrono::time(d)); + d.hour = hmsn.0; + d.minute = hmsn.1; + d.second = hmsn.2; + d.nanosecond = hmsn.3; + return d.second: int; case let s: int => return s; }; }; -fn _nanosecond(dt: *date) int = { - match (dt.nanosecond) { +fn _nanosecond(d: *date) int = { + match (d.nanosecond) { case void => - const hmsn = calc_hmsn(chrono::time(dt)); - dt.hour = hmsn.0; - dt.minute = hmsn.1; - dt.second = hmsn.2; - dt.nanosecond = hmsn.3; - return dt.nanosecond: int; + const hmsn = calc_hmsn(chrono::time(d)); + d.hour = hmsn.0; + d.minute = hmsn.1; + d.second = hmsn.2; + d.nanosecond = hmsn.3; + return d.nanosecond: int; case let n: int => return n; }; diff --git a/time/date/datetime.ha b/time/date/datetime.ha @@ -72,24 +72,24 @@ fn init() date = date { }; // Evaluates and populates all of a [[date]]'s fields. -fn all(dt: *date) *date = { - _era(dt); - _year(dt); - _month(dt); - _day(dt); - _yearday(dt); - _isoweekyear(dt); - _isoweek(dt); - _week(dt); - _sundayweek(dt); - _weekday(dt); +fn all(d: *date) *date = { + _era(d); + _year(d); + _month(d); + _day(d); + _yearday(d); + _isoweekyear(d); + _isoweek(d); + _week(d); + _sundayweek(d); + _weekday(d); - _hour(dt); - _minute(dt); - _second(dt); - _nanosecond(dt); + _hour(d); + _minute(d); + _second(d); + _nanosecond(d); - return dt; + return d; }; // Creates a new [[date]]. A maximum of 7 optional field arguments can be given: @@ -169,30 +169,30 @@ export fn new( abort("TODO: time::date::new(zo=void)"); }; - const dt = from_moment(m); + const d = from_moment(m); const zo = match (zo) { case void => yield chrono::mzone(&m).zoff; - case let d: time::duration => - yield d; + case let zo: time::duration => + yield zo; }; // check if input values are actually observed if ( - zo != chrono::mzone(&dt).zoff - || year != _year(&dt) - || month != _month(&dt) - || day != _day(&dt) - || hour != _hour(&dt) - || min != _minute(&dt) - || sec != _second(&dt) - || nsec != _nanosecond(&dt) + zo != chrono::mzone(&d).zoff + || year != _year(&d) + || month != _month(&d) + || day != _day(&d) + || hour != _hour(&d) + || min != _minute(&d) + || sec != _second(&d) + || nsec != _nanosecond(&d) ) { return invalid; }; - return dt; + return d; }; // Returns a [[date]] of the current system time using @@ -209,14 +209,14 @@ export fn nowutc() date = { // Creates a [[date]] from a [[time::chrono::moment]]. export fn from_moment(m: chrono::moment) date = { - const dt = init(); - dt.loc = m.loc; - dt.sec = m.sec; - dt.nsec = m.nsec; - dt.date = m.date; - dt.time = m.time; - dt.zone = m.zone; - return dt; + const d = init(); + d.loc = m.loc; + d.sec = m.sec; + d.nsec = m.nsec; + d.date = m.date; + d.time = m.time; + d.zone = m.zone; + return d; }; // Creates a [[date]] from a [[time::instant]] diff --git a/time/date/duration.ha b/time/date/duration.ha @@ -6,6 +6,6 @@ use time; // // See [[reckon]] for a chronology-wise arithmetic operation which uses // [[period]]. -export fn add(a: date, d: time::duration) date = { - return from_instant(a.loc, time::add(*(&a: *time::instant), d)); +export fn add(d: date, x: time::duration) date = { + return from_instant(d.loc, time::add(*(&d: *time::instant), x)); }; diff --git a/time/date/format.ha b/time/date/format.ha @@ -86,79 +86,79 @@ def MONTHS_SHORT: [_]str = [ export fn bsformat( buf: []u8, layout: str, - dt: *date, + d: *date, ) (str | io::error) = { let sink = strio::fixed(buf); - format(&sink, layout, dt)?; + format(&sink, layout, d)?; return strio::string(&sink); }; // Formats a [[date]] and writes it into a heap-allocated string. // The caller must free the return value. -export fn asformat(layout: str, dt: *date) (str | io::error) = { +export fn asformat(layout: str, d: *date) (str | io::error) = { let sink = strio::dynamic(); - format(&sink, layout, dt)?; + format(&sink, layout, d)?; return strio::string(&sink); }; -fn fmtout(out: io::handle, r: rune, dt: *date) (size | io::error) = { +fn fmtout(out: io::handle, r: rune, d: *date) (size | io::error) = { switch (r) { case 'a' => - return fmt::fprint(out, WEEKDAYS_SHORT[_weekday(dt)]); + return fmt::fprint(out, WEEKDAYS_SHORT[_weekday(d)]); case 'A' => - return fmt::fprint(out, WEEKDAYS[_weekday(dt)]); + return fmt::fprint(out, WEEKDAYS[_weekday(d)]); case 'b' => - return fmt::fprint(out, MONTHS_SHORT[_month(dt) - 1]); + return fmt::fprint(out, MONTHS_SHORT[_month(d) - 1]); case 'B' => - return fmt::fprint(out, MONTHS[_month(dt) - 1]); + return fmt::fprint(out, MONTHS[_month(d) - 1]); case 'd' => - return fmt::fprintf(out, "{:02}", _day(dt)); + return fmt::fprintf(out, "{:02}", _day(d)); case 'F' => - return fmt::fprintf(out, "{:04}-{:02}-{:02}", _year(dt), _month(dt), _day(dt)); + return fmt::fprintf(out, "{:04}-{:02}-{:02}", _year(d), _month(d), _day(d)); case 'H' => - return fmt::fprintf(out, "{:02}", _hour(dt)); + return fmt::fprintf(out, "{:02}", _hour(d)); case 'I' => - return fmt::fprintf(out, "{:02}", (_hour(dt) + 11) % 12 + 1); + return fmt::fprintf(out, "{:02}", (_hour(d) + 11) % 12 + 1); case 'j' => - return fmt::fprintf(out, "{:03}", _yearday(dt)); + return fmt::fprintf(out, "{:03}", _yearday(d)); case 'L' => - return fmt::fprint(out, dt.loc.name); + return fmt::fprint(out, d.loc.name); case 'm' => - return fmt::fprintf(out, "{:02}", _month(dt)); + return fmt::fprintf(out, "{:02}", _month(d)); case 'M' => - return fmt::fprintf(out, "{:02}", _minute(dt)); + return fmt::fprintf(out, "{:02}", _minute(d)); case 'N' => - return fmt::fprintf(out, "{:09}", _nanosecond(dt)); + return fmt::fprintf(out, "{:09}", _nanosecond(d)); case 'p' => - return fmt::fprint(out, if (_hour(dt) < 12) "AM" else "PM"); + return fmt::fprint(out, if (_hour(d) < 12) "AM" else "PM"); case 's' => - return fmt::fprintf(out, "{:02}", time::unix(*(dt: *time::instant))); + return fmt::fprintf(out, "{:02}", time::unix(*(d: *time::instant))); case 'S' => - return fmt::fprintf(out, "{:02}", _second(dt)); + return fmt::fprintf(out, "{:02}", _second(d)); case 'T' => - return fmt::fprintf(out, "{:02}:{:02}:{:02}", _hour(dt), _minute(dt), _second(dt)); + return fmt::fprintf(out, "{:02}:{:02}:{:02}", _hour(d), _minute(d), _second(d)); case 'u' => - return fmt::fprintf(out, "{}", _weekday(dt) + 1); + return fmt::fprintf(out, "{}", _weekday(d) + 1); case 'U' => - return fmt::fprintf(out, "{:02}", _sundayweek(dt)); + return fmt::fprintf(out, "{:02}", _sundayweek(d)); case 'w' => - return fmt::fprintf(out, "{}", (_weekday(dt) + 1) % 7); + return fmt::fprintf(out, "{}", (_weekday(d) + 1) % 7); case 'W' => - return fmt::fprintf(out, "{:02}", _week(dt)); + return fmt::fprintf(out, "{:02}", _week(d)); case 'y' => - return fmt::fprintf(out, "{:02}", _year(dt) % 100); + return fmt::fprintf(out, "{:02}", _year(d) % 100); case 'Y' => - return fmt::fprintf(out, "{:04}", _year(dt)); + return fmt::fprintf(out, "{:04}", _year(d)); case 'z' => - const (sign, zo) = if (chrono::mzone(dt).zoff >= 0) { - yield ('+', calc_hmsn(chrono::mzone(dt).zoff)); + const (sign, zo) = if (chrono::mzone(d).zoff >= 0) { + yield ('+', calc_hmsn(chrono::mzone(d).zoff)); } else { - yield ('-', calc_hmsn(-chrono::mzone(dt).zoff)); + yield ('-', calc_hmsn(-chrono::mzone(d).zoff)); }; const (hr, mi) = (zo.0, zo.1); return fmt::fprintf(out, "{}{:02}{:02}", sign, hr, mi); case 'Z' => - return fmt::fprint(out, chrono::mzone(dt).abbr); + return fmt::fprint(out, chrono::mzone(d).abbr); case '%' => return fmt::fprint(out, "%"); case => @@ -206,7 +206,7 @@ fn fmtout(out: io::handle, r: rune, dt: *date) (size | io::error) = { export fn format( h: io::handle, layout: str, - dt: *date + d: *date ) (size | io::error) = { const iter = strings::iter(layout); let escaped = false; @@ -221,7 +221,7 @@ export fn format( if (escaped) { escaped = false; - n += fmtout(h, r, dt)?; + n += fmtout(h, r, d)?; } else { if (r == '%') { escaped = true; @@ -234,7 +234,7 @@ export fn format( }; @test fn format() void = { - const dt = new(chrono::UTC, 0, 1994, 1, 1, 2, 17, 5, 24)!; + const d = new(chrono::UTC, 0, 1994, 1, 1, 2, 17, 5, 24)!; const cases = [ // special characters @@ -280,11 +280,11 @@ export fn format( for (let i = 0z; i < len(cases); i += 1) { const layout = cases[i].0; const expected = cases[i].1; - const actual = asformat(layout, &dt)!; + const actual = asformat(layout, &d)!; defer free(actual); if (actual != expected) { fmt::printfln( - "expected format({}, &dt) to be {} but was {}", + "expected format({}, &d) to be {} but was {}", layout, expected, actual )!; abort(); diff --git a/time/date/reckon.ha b/time/date/reckon.ha @@ -69,17 +69,17 @@ export type calculus = enum uint { // // See [[add]] for a timescale-wise arithmetic operation which uses // [[time::duration]]. -export fn reckon(dt: date, calc: calculus, ps: period...) date = { +export fn reckon(d: date, calc: calculus, ps: period...) date = { let r = newvirtual(); // our reckoner - r.vloc = dt.loc; - r.zoff = chrono::mzone(&dt).zoff; - r.year = _year(&dt); - r.month = _month(&dt); - r.day = _day(&dt); - r.hour = _hour(&dt); - r.minute = _minute(&dt); - r.second = _second(&dt); - r.nanosecond = _nanosecond(&dt); + r.vloc = d.loc; + r.zoff = chrono::mzone(&d).zoff; + r.year = _year(&d); + r.month = _month(&d); + r.day = _day(&d); + r.hour = _hour(&d); + r.minute = _minute(&d); + r.second = _second(&d); + r.nanosecond = _nanosecond(&d); if (calc == calculus::DEFAULT) { calc |= calculus::CEIL; diff --git a/time/date/timezone.ha b/time/date/timezone.ha @@ -8,6 +8,6 @@ use time::chrono; // [[time::chrono::locality]]. // // The [[time::chrono::discontinuity]] rules from [[time::chrono::in]] apply here. -export fn in(loc: chrono::locality, dt: date) (date | chrono::discontinuity) = { - return from_moment(chrono::in(loc, *(&dt: *chrono::moment))?); +export fn in(loc: chrono::locality, d: date) (date | chrono::discontinuity) = { + return from_moment(chrono::in(loc, *(&d: *chrono::moment))?); }; diff --git a/time/date/virtual.ha b/time/date/virtual.ha @@ -28,7 +28,7 @@ export type insufficient = !void; // v.minute = 14; // v.second = 07; // v.nanosecond = 0; -// let dt = date::realize(v)!; +// let d = date::realize(v)!; // export type virtual = struct { date, @@ -208,7 +208,7 @@ export fn realize( }; // determine .sec, .nsec - const dt = from_moment(chrono::from_datetime( + const d = from_moment(chrono::from_datetime( v.loc, v.zoff as time::duration, v.date as i64, @@ -216,10 +216,10 @@ export fn realize( )); // verify zone offset - const z = chrono::mzone(&dt); + const z = chrono::mzone(&d); if (z.zoff != v.zoff as time::duration) { return invalid; }; - return dt; + return d; };