summaryrefslogtreecommitdiff
path: root/lib/date
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-11-07 14:49:33 -0800
committerOri Bernstein <ori@eigenstate.org>2015-11-07 14:49:33 -0800
commitb84692c0fbbd771deab1e8fb75a7f83585c24253 (patch)
treefeadefa81a36a26679b2500ab8cd8bbf5047e679 /lib/date
parent01be94abcf0a010b24bc7f7b177bf40c5c45b7f1 (diff)
downloadmc-b84692c0fbbd771deab1e8fb75a7f83585c24253.tar.gz
Pass the time zone offset through everywhere.
We don't always have a zone name, eg, when parsing from a string.
Diffstat (limited to 'lib/date')
-rw-r--r--lib/date/date.myr39
-rw-r--r--lib/date/zoneinfo+posixy.myr4
2 files changed, 27 insertions, 16 deletions
diff --git a/lib/date/date.myr b/lib/date/date.myr
index 8ccb4d1..e9e82b1 100644
--- a/lib/date/date.myr
+++ b/lib/date/date.myr
@@ -34,7 +34,7 @@ const DayUsec = (24*60*60*1_000_000)
const Mdays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
const utcnow = {
- -> mkinstant(std.now(), "")
+ -> mkinstantoff(std.now(), "", 0)
}
const now = {tz : byte[:]
@@ -53,13 +53,27 @@ const mkdate = {y, m, d, tz
}
const mkdatetime = {year, mon, day, h, m, s, tz
- -> mkinstant(recalc(&[
- .year=year, .mon=mon, .day=day,
- .h=h, .m=m, .s=s
- ]), tz)
+ var tm
+
+ tm = recalc(&[.year=year, .mon=mon, .day=day,
+ .h=h, .m=m, .s=s,])
+
+ match _zoneinfo.findtzoff(tz, tm)
+ | `std.Some off:
+ -> mkinstantoff(tm, tz, off)
+ | `std.None:
+ std.fatal("invalid timezone {}\n", tz)
+ ;;
}
-const mkinstant = {tm, tz
+const mkinstant = {tm, tz
+ match _zoneinfo.findtzoff(tz, tm)
+ | `std.Some o: -> mkinstantoff(tm, tz, o)
+ | `std.None: std.fatal("no zone named {}\n", tz)
+ ;;
+}
+
+const mkinstantoff = {tm, tz, tzoff
var j, y, m, d
var t, e
var inst
@@ -67,12 +81,9 @@ const mkinstant = {tm, tz
inst.actual = tm
/* time zones */
std.assert(tz.len <= inst._tzbuf.len, "time zone name too long\n")
- match _zoneinfo.findtzoff(tz, tm)
- | `std.Some o: inst.tzoff = o
- | `std.None: std.fatal("no zone named {}\n", tz)
- ;;
std.slcp(inst._tzbuf[:tz.len], tz)
inst.tzname = inst._tzbuf[:tz.len]
+ inst.tzoff = tzoff
tm += inst.tzoff castto(std.time)
/* break up time */
@@ -162,11 +173,11 @@ const isleap = {d
}
const add = {d, dt
- -> mkinstant(d.actual + (dt castto(std.time)), d.tzname)
+ -> mkinstantoff(d.actual + (dt castto(std.time)), d.tzname, d.tzoff)
}
const sub = {d, dt
- -> mkinstant(d.actual - (dt castto(std.time)), d.tzname)
+ -> mkinstantoff(d.actual - (dt castto(std.time)), d.tzname, d.tzoff)
}
const addperiod = {inst, p
@@ -178,7 +189,7 @@ const addperiod = {inst, p
| `Minute m: inst.m += m
| `Second s: inst.s += s
;;
- -> mkinstant(recalc(&inst), inst.tzname)
+ -> mkinstantoff(recalc(&inst), inst.tzname, inst.tzoff)
}
const subperiod = {inst, p
@@ -190,7 +201,7 @@ const subperiod = {inst, p
| `Minute m: inst.m -= m
| `Second s: inst.s -= s
;;
- -> mkinstant(recalc(&inst), inst.tzname)
+ -> mkinstantoff(recalc(&inst), inst.tzname, inst.tzoff)
}
const duration = {a, b
diff --git a/lib/date/zoneinfo+posixy.myr b/lib/date/zoneinfo+posixy.myr
index 7905f96..df4395a 100644
--- a/lib/date/zoneinfo+posixy.myr
+++ b/lib/date/zoneinfo+posixy.myr
@@ -84,8 +84,8 @@ const load = {file
-> std.zalloc()
;;
- if !std.sleq(p[:4], "TZif\0")
- std.put("%s is not a zone info file\n", file)
+ if !std.sleq(p[:4], "TZif")
+ std.put("{} is not a zone info file\n", file)
-> std.zalloc()
;;