ref: b10b3137d2423629ee2641bf178196e243697c20
parent: 3dd66ec7cb4541a8909e2e4fc6da8d733f1ae0db
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jan 3 13:16:40 EST 2015
Fix namespace conflicts. date.foo doesn't work in namespace 'date'.
--- a/lib/date/date.myr
+++ b/lib/date/date.myr
@@ -45,16 +45,16 @@
const mkinstant = {tm, tz
var j, y, m, d
var t, e
- var date
+ var inst
var off
- date.actual = tm
+ inst.actual = tm
/* time zones */
- std.assert(tz.len <= date._tzbuf.len, "time zone name too long\n")
+ std.assert(tz.len <= inst._tzbuf.len, "time zone name too long\n")
off =_zoneinfo.findtzoff(tz, tm)
- date.tzoff = off
- std.slcp(date._tzbuf[:tz.len], tz)
- date.tzname = date._tzbuf[:tz.len]
+ inst.tzoff = off
+ std.slcp(inst._tzbuf[:tz.len], tz)
+ inst.tzname = inst._tzbuf[:tz.len]
tm += off castto(std.time)
/* break up time */
@@ -63,16 +63,16 @@
/* microseconds, seconds, minutes, hours */
- date.us = (t % 1_000_000) castto(int)
+ inst.us = (t % 1_000_000) castto(int)
t /= 1_000_000
- date.s = (t % 60) castto(int)
+ inst.s = (t % 60) castto(int)
t /= 60
- date.m = (t % 60) castto(int)
+ inst.m = (t % 60) castto(int)
t /= 60
- date.h = t castto(int)
+ inst.h = t castto(int)
/* weekday */
- date.wday = ((e + 4) % 7) castto(int) /* the world started on Thursday */
+ inst.wday = ((e + 4) % 7) castto(int) /* the world started on Thursday */
/*
split up year, month, day.
@@ -100,10 +100,10 @@
m -= 9
y++
;;
- date.year = y castto(int)
- date.mon = m castto(int)
- date.day = (d + 1) castto(int)
- -> date
+ inst.year = y castto(int)
+ inst.mon = m castto(int)
+ inst.day = (d + 1) castto(int)
+ -> inst
}
const localoff = {tm
--- a/lib/date/fmt.myr
+++ b/lib/date/fmt.myr
@@ -72,6 +72,7 @@
| 'z': o += timezone(buf[o:], d.tzoff)
| 'Z': o += std.bfmt(buf[o:], "%s", d.tzname)
| '%': o += std.bfmt(buf[o:], "%%")
+ | _: std.fatal(1, "unknown format character %c\n", c)
;;
else
o += std.bfmt(buf[o:], "%c", c)
--- a/lib/date/parse.myr
+++ b/lib/date/parse.myr
@@ -114,6 +114,7 @@
| 'Z': o += std.bfmt(buf[o:], "%s", d.tzname)
*/
| '%': s = matchstr(s, "%", err)
+ | _: std.fatal(1, "unknown format character %c\n", fc)
;;
else
(sc, s) = std.striter(s)
@@ -199,17 +200,17 @@
;;
}
-const time = {date
+const time = {inst
var t
var c, y, ya, m, u
t = 0
- if date.mon > 2
- m = (date.mon - 3) castto(std.time)
+ if inst.mon > 2
+ m = (inst.mon - 3) castto(std.time)
else
- m = (date.mon + 9) castto(std.time)
- y = (date.year - 1) castto(std.time)
+ m = (inst.mon + 9) castto(std.time)
+ y = (inst.year - 1) castto(std.time)
;;
c = y / 100
@@ -217,13 +218,13 @@
u = (146097 * c) / 4 + \
(1461 * ya) / 4 + \
(153 * m + 2) / 5 + \
- (date.day castto(std.time)) + \
+ (inst.day castto(std.time)) + \
UnixJulianDiff
t += (u * 24*60*60*1_000_000)
- t += (date.h castto(std.time)) * 60*60*1_000_000
- t += (date.m castto(std.time)) * 60*1_000_000
- t += (date.s castto(std.time)) * 1_000_000
- t += date.us castto(std.time)
+ t += (inst.h castto(std.time)) * 60*60*1_000_000
+ t += (inst.m castto(std.time)) * 60*1_000_000
+ t += (inst.s castto(std.time)) * 1_000_000
+ t += inst.us castto(std.time)
-> t
}