commit 2af3a7751ccc9f453066718cf9096103e41574e3
parent 10942dfa475a866ba79e7232018e3898cc0b6d17
Author: Byron Torres <b@torresjrjr.com>
Date: Thu, 23 Jun 2022 17:05:37 +0100
time::chrono,datetime: rename min, sec, nsec
This is in preparation for the next commit.
* min -> minute
* sec -> second
* nsec -> nanosecond
Diffstat:
5 files changed, 52 insertions(+), 52 deletions(-)
diff --git a/datetime/arithmetic.ha b/datetime/arithmetic.ha
@@ -113,19 +113,19 @@ export fn diff(a: datetime, b: datetime) period = {
res.hours = 24 + res.hours;
};
- res.minutes = min(&a) - min(&b);
+ res.minutes = minute(&a) - minute(&b);
if (res.minutes < 0) {
res.hours -= 1;
res.minutes = 60 + res.minutes;
};
- res.seconds = sec(&a) - sec(&b);
+ res.seconds = second(&a) - second(&b);
if (res.seconds < 0) {
res.minutes -= 1;
res.seconds = 60 + res.seconds;
};
- res.nanoseconds = nsec(&a) - nsec(&b);
+ res.nanoseconds = nanosecond(&a) - nanosecond(&b);
if (res.nanoseconds < 0) {
res.seconds -= 1;
res.nanoseconds = time::SECOND + res.nanoseconds;
@@ -221,12 +221,12 @@ export fn truncate(dt: datetime, u: unit) datetime = {
case unit::MINUTE =>
yield new(dt.loc, 0,
year(&dt), month(&dt), day(&dt),
- hour(&dt), min(&dt), 0, 0,
+ hour(&dt), minute(&dt), 0, 0,
)!;
case unit::SECOND =>
yield new(dt.loc, 0,
year(&dt), month(&dt), day(&dt),
- hour(&dt), min(&dt), sec(&dt), 0,
+ hour(&dt), minute(&dt), second(&dt), 0,
)!;
case unit::NANOSECOND =>
yield dt;
@@ -316,9 +316,9 @@ export fn add(dt: datetime, flag: calculus, pp: period...) datetime = {
let d_month = month(&dt);
let d_day = day(&dt);
let d_hour = hour(&dt);
- let d_min = min(&dt);
- let d_sec = sec(&dt);
- let d_nsec = ((nsec(&dt)): i64);
+ let d_minute = minute(&dt);
+ let d_second = second(&dt);
+ let d_nanosecond = ((nanosecond(&dt)): i64);
for (let i = 0z; i < len(pp); i += 1) {
const p = pp[i];
@@ -396,14 +396,14 @@ export fn add(dt: datetime, flag: calculus, pp: period...) datetime = {
};
const new_hmsn = calc_hmsn(new_time);
d_hour = new_hmsn.0;
- d_min = new_hmsn.1;
- d_sec = new_hmsn.2;
- d_nsec = new_hmsn.3;
+ d_minute = new_hmsn.1;
+ d_second = new_hmsn.2;
+ d_nanosecond = new_hmsn.3;
};
};
// TODO: Add zoffset back in here once API is settled
return new(dt.loc, 0,
- d_year, d_month, d_day, d_hour, d_min, d_sec, d_nsec: int,
+ d_year, d_month, d_day, d_hour, d_minute, d_second, d_nanosecond: int,
)!;
};
diff --git a/datetime/chronology.ha b/datetime/chronology.ha
@@ -50,13 +50,13 @@ export fn isoweek(dt: *datetime) int = _isoweek(dt);
export fn hour(dt: *datetime) int = _hour(dt);
// Returns a [[datetime]]'s minute of the hour.
-export fn min(dt: *datetime) int = _min(dt);
+export fn minute(dt: *datetime) int = _minute(dt);
// Returns a [[datetime]]'s second of the minute.
-export fn sec(dt: *datetime) int = _sec(dt);
+export fn second(dt: *datetime) int = _second(dt);
// Returns a [[datetime]]'s nanosecond of the second.
-export fn nsec(dt: *datetime) int = _nsec(dt);
+export fn nanosecond(dt: *datetime) int = _nanosecond(dt);
fn _epochal(dt: *datetime) chrono::date = {
const ldt = transform(*dt, dt.zone.zoffset);
@@ -246,55 +246,55 @@ fn _hour(dt: *datetime) int = {
case void =>
const hmsn = calc_hmsn(ldt.time: time::duration);
dt.hour = hmsn.0;
- dt.min = hmsn.1;
- dt.sec = hmsn.2;
- dt.nsec = hmsn.3;
+ dt.minute = hmsn.1;
+ dt.second = hmsn.2;
+ dt.nanosecond = hmsn.3;
return dt.hour: int;
case let h: int =>
return h;
};
};
-fn _min(dt: *datetime) int = {
+fn _minute(dt: *datetime) int = {
const ldt = transform(*dt, dt.zone.zoffset);
- match (dt.min) {
+ match (dt.minute) {
case void =>
const hmsn = calc_hmsn(ldt.time: time::duration);
dt.hour = hmsn.0;
- dt.min = hmsn.1;
- dt.sec = hmsn.2;
- dt.nsec = hmsn.3;
- return dt.min: int;
+ dt.minute = hmsn.1;
+ dt.second = hmsn.2;
+ dt.nanosecond = hmsn.3;
+ return dt.minute: int;
case let m: int =>
return m;
};
};
-fn _sec(dt: *datetime) int = {
+fn _second(dt: *datetime) int = {
const ldt = transform(*dt, dt.zone.zoffset);
- match (dt.sec) {
+ match (dt.second) {
case void =>
const hmsn = calc_hmsn(ldt.time: time::duration);
dt.hour = hmsn.0;
- dt.min = hmsn.1;
- dt.sec = hmsn.2;
- dt.nsec = hmsn.3;
- return dt.sec: int;
+ dt.minute = hmsn.1;
+ dt.second = hmsn.2;
+ dt.nanosecond = hmsn.3;
+ return dt.second: int;
case let s: int =>
return s;
};
};
-fn _nsec(dt: *datetime) int = {
+fn _nanosecond(dt: *datetime) int = {
const ldt = transform(*dt, dt.zone.zoffset);
- match (dt.nsec) {
+ match (dt.nanosecond) {
case void =>
const hmsn = calc_hmsn(ldt.time: time::duration);
dt.hour = hmsn.0;
- dt.min = hmsn.1;
- dt.sec = hmsn.2;
- dt.nsec = hmsn.3;
- return dt.nsec: int;
+ dt.minute = hmsn.1;
+ dt.second = hmsn.2;
+ dt.nanosecond = hmsn.3;
+ return dt.nanosecond: int;
case let n: int =>
return n;
};
diff --git a/datetime/datetime.ha b/datetime/datetime.ha
@@ -23,9 +23,9 @@ export type datetime = struct {
weekday: (void | int),
hour: (void | int),
- min: (void | int),
- sec: (void | int),
- nsec: (void | int),
+ minute: (void | int),
+ second: (void | int),
+ nanosecond: (void | int),
};
fn init() datetime = datetime {
@@ -46,9 +46,9 @@ fn init() datetime = datetime {
weekday = void,
hour = void,
- min = void,
- sec = void,
- nsec = void,
+ minute = void,
+ second = void,
+ nanosecond = void,
};
// Creates a new datetime. When loc=void, defaults to chrono::local.
@@ -146,9 +146,9 @@ export fn new(
&& month == _month(&dt)
&& day == _day(&dt)
&& hour == _hour(&dt)
- && min == _min(&dt)
- && sec == _sec(&dt)
- && nsec == _nsec(&dt)
+ && min == _minute(&dt)
+ && sec == _second(&dt)
+ && nsec == _nanosecond(&dt)
) {
void;
} else {
diff --git a/datetime/format.ha b/datetime/format.ha
@@ -122,9 +122,9 @@ fn fmtout(out: io::handle, r: rune, dt: *datetime) (size | io::error) = {
case 'm' =>
return fmt::fprintf(out, "{:02}", month(dt));
case 'M' =>
- return fmt::fprintf(out, "{:02}", min(dt));
+ return fmt::fprintf(out, "{:02}", minute(dt));
case 'N' =>
- return fmt::fprintf(out, "{:09}", strconv::itos(nsec(dt)));
+ return fmt::fprintf(out, "{:09}", strconv::itos(nanosecond(dt)));
case 'p' =>
const s = if (hour(dt) < 12) {
yield "AM";
@@ -135,9 +135,9 @@ fn fmtout(out: io::handle, r: rune, dt: *datetime) (size | io::error) = {
case 's' =>
return fmt::fprintf(out, "{:02}", epochunix(dt));
case 'S' =>
- return fmt::fprintf(out, "{:02}", sec(dt));
+ return fmt::fprintf(out, "{:02}", second(dt));
case 'T' =>
- return fmt::fprintf(out, "{:02}:{:02}:{:02}", hour(dt), min(dt), sec(dt));
+ return fmt::fprintf(out, "{:02}:{:02}:{:02}", hour(dt), minute(dt), second(dt));
case 'u' =>
return fmt::fprint(out, strconv::itos(weekday(dt)));
case 'U' =>
diff --git a/datetime/parse.ha b/datetime/parse.ha
@@ -89,10 +89,10 @@ export fn parse(build: *builder, layout: str, s: str) (void | invalid) = {
build.month = clamp_int(
get_max_n_digits(&s_iter, 2)?, 1, 12);
case 'M' =>
- build.min = clamp_int(
+ build.minute = clamp_int(
get_max_n_digits(&s_iter, 2)?, 0, 59);
case 'N' =>
- build.nsec = clamp_int(
+ build.nanosecond = clamp_int(
get_max_n_digits(&s_iter, 9)?, 0, 999999999);
case 'p' =>
if (build.hour is void) {
@@ -122,7 +122,7 @@ export fn parse(build: *builder, layout: str, s: str) (void | invalid) = {
strings::next(&s_iter);
strings::next(&s_iter);
case 'S' =>
- build.sec = clamp_int(
+ build.second = clamp_int(
get_max_n_digits(&s_iter, 2)?, 0, 61);
case 'u', 'w' =>
build.weekday = match (get_max_n_digits(&s_iter, 1)) {