hare

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

commit a4a1118680f3c77cb2329950ede4aab5fa91d9fe
parent f541578df9172214a93e41ed14f02543780268ba
Author: Byron Torres <b@torresjrjr.com>
Date:   Tue, 16 Nov 2021 16:10:09 +0000

correct year(), month(), day(), weekday()

Signed-off-by: Byron Torres <b@torresjrjr.com>

Diffstat:
Mdatetime/calendar.ha | 52+++++++++++++++++++++++++---------------------------
1 file changed, 25 insertions(+), 27 deletions(-)

diff --git a/datetime/calendar.ha b/datetime/calendar.ha @@ -73,14 +73,14 @@ export fn era(dt: *datetime) int = { export fn year(dt: *datetime) int = { match (dt.date.year) { case void => - match (dt.date.epochal) { - case void => - abort("TODO"); - case e: int => - const ymd = calc_ymd(e); - dt.date.year = ymd.0; - return dt.date.year: int; + if (dt.date.epochal is void) { + epochal(dt); }; + const ymd = calc_ymd(dt.date.epochal: int); + dt.date.year = ymd.0; + dt.date.month = ymd.1; + dt.date.day = ymd.2; + return dt.date.year: int; case y: int => return y; }; @@ -90,14 +90,14 @@ export fn year(dt: *datetime) int = { export fn month(dt: *datetime) int = { match (dt.date.month) { case void => - match (dt.date.epochal) { - case void => - abort("TODO"); - case e: int => - const ymd = calc_ymd(e); - dt.date.month = ymd.1; - return dt.date.month: int; + if (dt.date.epochal is void) { + epochal(dt); }; + const ymd = calc_ymd(dt.date.epochal: int); + dt.date.year = ymd.0; + dt.date.month = ymd.1; + dt.date.day = ymd.2; + return dt.date.month: int; case y: int => return y; }; @@ -107,14 +107,14 @@ export fn month(dt: *datetime) int = { export fn day(dt: *datetime) int = { match (dt.date.day) { case void => - match (dt.date.epochal) { - case void => - abort("TODO"); - case e: int => - const ymd = calc_ymd(e); - dt.date.day = ymd.2; - return dt.date.day: int; + if (dt.date.epochal is void) { + epochal(dt); }; + const ymd = calc_ymd(dt.date.epochal: int); + dt.date.year = ymd.0; + dt.date.month = ymd.1; + dt.date.day = ymd.2; + return dt.date.day: int; case y: int => return y; }; @@ -125,13 +125,11 @@ export fn day(dt: *datetime) int = { export fn weekday(dt: *datetime) int = { match (dt.date.weekday) { case void => - match (dt.date.epochal) { - case void => - abort("TODO"); - case e: int => - dt.date.weekday = calc_weekday(e); - return dt.date.weekday: int; + if (dt.date.epochal is void) { + epochal(dt); }; + dt.date.weekday = calc_weekday(dt.date.epochal: int); + return dt.date.weekday: int; case y: int => return y; };