commit d175a565cee80690e09ee41d4a3e0b2beabfae94
parent 73967c5db7a596fe8d70d90a27d8492b21c82b7a
Author: Byron Torres <b@torresjrjr.com>
Date: Wed, 15 Dec 2021 20:57:46 +0000
codify timezone transitions
Signed-off-by: Byron Torres <b@torresjrjr.com>
Diffstat:
3 files changed, 24 insertions(+), 62 deletions(-)
diff --git a/datetime/timezone.ha b/datetime/timezone.ha
@@ -24,15 +24,14 @@ export fn tzdb(name: str) chrono::timezone = {
//
// "Europe/Amsterdam" timezone
-export const TZ_Europe_Amsterdam: chrono::timezone = chrono::timezone {
- aliasof = &TZ_CET,
+export const TZ_Europe_Amsterdam: chrono::tzalias = chrono::tzalias {
name = "Europe/Amsterdam",
- ...
+ tz = &TZ_CET,
};
// "CET", "Central European Time" timezone
export const TZ_CET: chrono::timezone = chrono::timezone {
- aliasof = void,
+ name = "CET",
scale = &chrono::UTC,
zones = [
chrono::zone {
@@ -48,32 +47,5 @@ export const TZ_CET: chrono::timezone = chrono::timezone {
dst = true,
},
],
- applied = &zone_cet,
- name = "CET",
-};
-
-fn zone_cet(m: chrono::moment) uint = {
- const dt = datetime { ... };
- // TODO: reconcile chrono::moment // datetime::datetime types
- //conv_moment_datetime(m, &dt);
- const dst = (
- dt.date.month: int == 3 &&
- dt.date.day: int == 28 &&
- dt.time.hour: int >= 2
- ) || (
- dt.date.month: int > 3 && dt.date.month: int < 8
- ) || (
- dt.date.month: int == 8 &&
- dt.date.day: int < 31
- ) || (
- dt.date.month: int == 8 &&
- dt.date.day: int == 31 &&
- dt.time.hour: int <= 3
- );
-
- if (dst) {
- return 1u;
- } else {
- return 0u;
- };
+ trans = [],
};
diff --git a/time/chrono/chronology.ha b/time/chrono/chronology.ha
@@ -1,13 +1,5 @@
use time;
-// // A chronological system for ordering days as dates and eras
-// export type chronology = struct {
-// to_taidate: nullable *fn(n: moment) moment,
-// from_taidate: nullable *fn(n: moment) moment,
-//
-// scale: timescale,
-// };
-
// A date & time within a locality, to be contextualised in a chronology
export type moment = struct {
date: epochal,
@@ -16,10 +8,4 @@ export type moment = struct {
};
// An ordinal day on earth since the calendar epoch (zeroth day) 1970-01-01
-//
-// Notes:
-// 1970-01-01 is "the Hare date-epoch". It was chosen out of simplicity to match
-// the UNIX timescale epoch. This shouldn't affect performance in calendar
-// implementations because they can convert to other epochs if they so desire.
-// (as of writing) datetime:: converts to the Julian epoch for calculations.
export type epochal = i64;
diff --git a/time/chrono/timezone.ha b/time/chrono/timezone.ha
@@ -1,7 +1,7 @@
use time;
// Represents the locality of a datetime
-export type locality = (local | zoffset | *timezone);
+export type locality = (local | zoffset | *timezone | *tzalias);
// Represents its associated datetime as local
export type local = void;
@@ -9,6 +9,14 @@ export type local = void;
// Represents a simple, constant zone offset
export type zoffset = time::duration;
+// Represents a timezone; a political region with a ruleset regarding offsets
+export type timezone = struct {
+ name: str, // "Europe/Amsterdam"
+ scale: *timescale,
+ zones: []zone,
+ trans: []zonetran,
+};
+
// Represents a conditional offset, dependant on the time of year
export type zone = struct {
zoffset: zoffset, // 2 * time::HOUR
@@ -17,17 +25,18 @@ export type zone = struct {
dst: bool, // true
};
-// Represents a timezone; a political region with a ruleset regarding offsets
-export type timezone = struct {
- aliasof: (void | *timezone),
- scale: *timescale,
- zones: []zone,
- applied: *fn(m: moment) uint,
- name: str, // "Europe/Amsterdam"
+// Represents a timezone transition
+export type zonetran = struct {
+ when: time::instant,
+ zoneindex: int,
+};
+
+export type tzalias = struct {
+ name: str,
+ tz: *timezone,
};
export const TZ_UTC: timezone = timezone {
- aliasof = void,
scale = &UTC,
zones = [
zone {
@@ -37,12 +46,11 @@ export const TZ_UTC: timezone = timezone {
dst = false,
},
],
- applied = &zone_const,
+ trans = [],
name = "Etc/UTC",
};
export const TZ_TAI: timezone = timezone {
- aliasof = void,
scale = &TAI,
zones = [
zone {
@@ -52,10 +60,6 @@ export const TZ_TAI: timezone = timezone {
dst = false,
},
],
- applied = &zone_const,
+ trans = [],
name = "",
};
-
-fn zone_const(m: moment) uint = {
- return 0u;
-};