commit ee6bbf85490c236f90e4eb789a8e9eb2eb77719d
parent 4535c99aadc6b6765007242abd877580bfe3f47e
Author: Autumn! <autumnull@posteo.net>
Date: Tue, 9 May 2023 22:37:58 +0000
time::chrono: lazily load utc leapsecs
Signed-off-by: Autumn! <autumnull@posteo.net>
Diffstat:
2 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/time/chrono/leapsec.ha b/time/chrono/leapsec.ha
@@ -46,17 +46,6 @@ let utc_leapsecs: [](i64, i64) = [];
let utc_isinitialized: bool = false;
-// Initializes the [[utc]] [[timescale]].
-@init fn init_utc() void = {
- os::init_cwd();
- match (init_utc_leapsecs()) {
- case void =>
- utc_isinitialized = true;
- case =>
- return;
- };
-};
-
@fini fn free_utc() void = {
free(utc_leapsecs);
};
diff --git a/time/chrono/timescale.ha b/time/chrono/timescale.ha
@@ -135,7 +135,12 @@ fn utc_convto(ts: *timescale, i: time::instant) ([]time::instant | void) = {
return [i];
case &tai =>
if (!utc_isinitialized) {
- abort("utc timescale uninitialized");
+ match (init_utc_leapsecs()) {
+ case void =>
+ utc_isinitialized = true;
+ case =>
+ abort("utc timescale uninitialized");
+ };
};
const idx = lookup_leaps(&utc_leapsecs, time::unix(i));
@@ -162,7 +167,12 @@ fn utc_convfrom(ts: *timescale, i: time::instant) ([]time::instant | void) = {
return [i];
case &tai =>
if (!utc_isinitialized) {
- abort("utc timescale uninitialized");
+ match (init_utc_leapsecs()) {
+ case void =>
+ utc_isinitialized = true;
+ case =>
+ abort("utc timescale uninitialized");
+ };
};
const idx = lookup_leaps(&utc_leapsecs, time::unix(i));