commit efc49cf4f4ad16986ad056abe2c0bdb9bc769e55
parent 241abef48b6546c80842806fd9a7a1becf167249
Author: Drew DeVault <sir@cmpwn.com>
Date: Wed, 13 Apr 2022 13:44:56 +0200
datetime et al: updates per stdlib/compiler changes
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
8 files changed, 31 insertions(+), 19 deletions(-)
diff --git a/datetime/arithmetic.ha b/datetime/arithmetic.ha
@@ -127,7 +127,7 @@ export fn diff(a: datetime, b: datetime) period = {
export fn diff_in_unit(a: datetime, b: datetime, u: unit) i64 = {
return switch (u) {
case unit::ERA =>
- yield math::absi(era(&a) - era(&b));
+ yield math::absi(era(&a) - era(&b)): i64;
case unit::YEAR =>
yield diff(a, b).years;
case unit::MONTH =>
@@ -354,7 +354,7 @@ export fn add(dt: datetime, flag: calculus, pp: period...) datetime = {
const ns_in_day = 24 * time::HOUR;
let overflowed_days = 0;
- if (math::absi(p.nanoseconds) > ns_in_day) {
+ if (math::absi(p.nanoseconds): i64 > ns_in_day) {
overflowed_days +=
((p.nanoseconds / ns_in_day): int);
p.nanoseconds %= ns_in_day;
diff --git a/datetime/datetime.ha b/datetime/datetime.ha
@@ -314,7 +314,7 @@ export type strategy = enum uint {
};
@test fn clone() void = {
- let d0 = datetime::new(chrono::UTC, 0, 2038, 01, 19, 03, 14, 07, 0)!;
+ let d0 = new(chrono::UTC, 0, 2038, 01, 19, 03, 14, 07, 0)!;
let d1 = clone(d0);
assert(d0.year as int == d1.year as int &&
d0.month as int == d1.month as int &&
diff --git a/datetime/format.ha b/datetime/format.ha
@@ -174,7 +174,7 @@ export fn fmtstream(
};
fn get_default_locale_string_index(iter: *strings::iterator, list: []str) (int | invalid) = {
- const name = strings::iter_str(iter);
+ const name = strings::iterstr(iter);
if (len(name) == 0) {
return invalid;
};
diff --git a/datetime/parse.ha b/datetime/parse.ha
@@ -92,7 +92,7 @@ export fn parse(mok: *mock, layout: str, s: str) (void | invalid) = {
// have no hour.
return invalid;
};
- const rest = strings::iter_str(&s_iter);
+ const rest = strings::iterstr(&s_iter);
if (strings::hasprefix(rest, "AM")) {
if (mok.hour as int > 12) {
// 13 AM?
diff --git a/time/chrono/chronology.ha b/time/chrono/chronology.ha
@@ -71,4 +71,4 @@ export def EARTH_DAY: time::duration = 86400 * time::SECOND;
export def MARS_SOL_MARTIAN: time::duration = 86400 * time::SECOND;
// The temporal length of a solar day on Marth, in Earth (SI) seconds
-export def MARS_SOL_TERRESTRIAL: time::duration = 88775.244147 * time::SECOND;
+export def MARS_SOL_TERRESTRIAL: time::duration = (88775.244147 * time::SECOND: f64): time::duration;
diff --git a/time/chrono/leapsec.ha b/time/chrono/leapsec.ha
@@ -57,7 +57,7 @@ fn read_leapsecfile(h: io::handle, leapsecs: *[](i64, i64)) (void | io::error) =
if (strings::hasprefix(line, '#')) {
continue;
};
- const pair = strings::splitN(line, "\t", 3);
+ const pair = strings::splitn(line, "\t", 3);
if (len(pair) < 2) {
continue;
};
diff --git a/time/chrono/timescale.ha b/time/chrono/timescale.ha
@@ -144,7 +144,7 @@ export const TT: timescale = timescale {
from_tai = &conv_tai_tt,
};
-def TT_OFFSET: time::duration = 32.184 * time::SECOND;
+def TT_OFFSET: time::duration = (32.184 * time::SECOND: f64): time::duration;
fn conv_tai_tt(a: time::instant) (time::instant | time::error) = {
const tt = time::instant {
diff --git a/time/tzdb/tzdb.ha b/time/tzdb/tzdb.ha
@@ -154,28 +154,28 @@ fn parse_tzif(
const transition_times: []i64 = [];
if (is64) {
- readitems8(h, &transition_times, timecnt);
+ readitems8(h, &transition_times, timecnt)?;
} else {
- readitems4(h, &transition_times, timecnt);
+ readitems4(h, &transition_times, timecnt)?;
};
const zone_indicies: []u8 = [];
- readbytes(h, &zone_indicies, timecnt);
+ readbytes(h, &zone_indicies, timecnt)?;
const zonedata: []u8 = [];
- readbytes(h, &zonedata, typecnt * 6);
+ readbytes(h, &zonedata, typecnt * 6)?;
const abbrdata: []u8 = [];
- readbytes(h, &abbrdata, charcnt);
+ readbytes(h, &abbrdata, charcnt)?;
const leapdata: []u8 = [];
- readbytes(h, &leapdata, leapcnt * (timesz: u32 + 4));
+ readbytes(h, &leapdata, leapcnt * (timesz: u32 + 4))?;
const stdwalldata: []u8 = [];
- readbytes(h, &stdwalldata, isstdcnt);
+ readbytes(h, &stdwalldata, isstdcnt)?;
const normlocaldata: []u8 = [];
- readbytes(h, &normlocaldata, isutcnt);
+ readbytes(h, &normlocaldata, isutcnt)?;
// read footer
@@ -285,7 +285,11 @@ fn read(h: io::handle, buf: []u8) (void | invalidtzif | io::error) = {
};
};
-fn readbytes(h: io::handle, items: *[]u8, n: size) void = {
+fn readbytes(
+ h: io::handle,
+ items: *[]u8,
+ n: size,
+) (void | invalidtzif | io::error) = {
const buf: [1]u8 = [0];
for (let i = 0z; i < n; i += 1) {
read(h, buf)?;
@@ -294,7 +298,11 @@ fn readbytes(h: io::handle, items: *[]u8, n: size) void = {
};
};
-fn readitems8(h: io::handle, items: *[]i64, n: size) void = {
+fn readitems8(
+ h: io::handle,
+ items: *[]i64,
+ n: size,
+) (void | invalidtzif | io::error) = {
const buf: [8]u8 = [0...];
for (let i = 0z; i < n; i += 1) {
read(h, buf)?;
@@ -303,7 +311,11 @@ fn readitems8(h: io::handle, items: *[]i64, n: size) void = {
};
};
-fn readitems4(h: io::handle, items: *[]i64, n: size) void = {
+fn readitems4(
+ h: io::handle,
+ items: *[]i64,
+ n: size,
+) (void | invalidtzif | io::error) = {
const buf: [4]u8 = [0...];
for (let i = 0z; i < n; i += 1) {
read(h, buf)?;