summaryrefslogtreecommitdiff
path: root/lib/date
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-05-17 22:00:50 -0700
committerOri Bernstein <ori@eigenstate.org>2016-05-17 22:00:50 -0700
commit7aac15b2bfcc5eec279aa14f9f199685f9d7e0d9 (patch)
treec9434a55ea6850aee7103f608c6333cfe3148d60 /lib/date
parentc96238b89583ed91e92ad909c507797d00015e95 (diff)
downloadmc-7aac15b2bfcc5eec279aa14f9f199685f9d7e0d9.tar.gz
New syntax for casts.
Diffstat (limited to 'lib/date')
-rw-r--r--lib/date/date.myr43
-rw-r--r--lib/date/fmt.myr4
-rw-r--r--lib/date/parse.myr23
-rw-r--r--lib/date/zoneinfo+posixy.myr24
4 files changed, 46 insertions, 48 deletions
diff --git a/lib/date/date.myr b/lib/date/date.myr
index 60fb3e3..bbfd326 100644
--- a/lib/date/date.myr
+++ b/lib/date/date.myr
@@ -14,7 +14,6 @@ pkg date =
const localoff : (tm : std.time -> duration)
const tzoff : (tzname : byte[:], tm : std.time -> duration)
- const tzname : (tzoff : int -> byte[:])
const isleap : (d : instant -> bool)
/* date differences */
@@ -84,7 +83,7 @@ const mkinstantoff = {tm, tz, tzoff
std.slcp(inst._tzbuf[:tz.len], tz)
inst.tzname = inst._tzbuf[:tz.len]
inst.tzoff = tzoff
- tm += inst.tzoff castto(std.time)
+ tm += (inst.tzoff : std.time)
/* break up time */
t = tm % DayUsec /* time */
@@ -96,16 +95,16 @@ const mkinstantoff = {tm, tz, tzoff
;;
/* microseconds, seconds, minutes, hours */
- inst.us = (t % 1_000_000) castto(int)
+ inst.us = (t % 1_000_000 : int)
t /= 1_000_000
- inst.s = (t % 60) castto(int)
+ inst.s = (t % 60 : int)
t /= 60
- inst.m = (t % 60) castto(int)
+ inst.m = (t % 60 : int)
t /= 60
- inst.h = t castto(int)
+ inst.h = (t : int)
/* weekday */
- inst.wday = ((e + 4) % 7) castto(int) /* the world started on Thursday */
+ inst.wday = ((e + 4) % 7 : int) /* the world started on Thursday */
/*
split up year, month, day.
@@ -151,9 +150,9 @@ const mkinstantoff = {tm, tz, tzoff
d += Mdays[m - 1]
;;
- inst.year = y castto(int)
- inst.mon = m castto(int)
- inst.day = d castto(int)
+ inst.year = (y : int)
+ inst.mon = (m : int)
+ inst.day = (d : int)
-> inst
}
@@ -173,11 +172,11 @@ const isleap = {d
}
const add = {d, dt
- -> mkinstantoff(d.actual + (dt castto(std.time)), d.tzname, d.tzoff)
+ -> mkinstantoff(d.actual + (dt : std.time), d.tzname, d.tzoff)
}
const sub = {d, dt
- -> mkinstantoff(d.actual - (dt castto(std.time)), d.tzname, d.tzoff)
+ -> mkinstantoff(d.actual - (dt : std.time), d.tzname, d.tzoff)
}
const addperiod = {inst, p
@@ -205,7 +204,7 @@ const subperiod = {inst, p
}
const duration = {a, b
- -> (b.actual - a.actual) castto(duration)
+ -> (b.actual - a.actual : duration)
}
const recalc = {inst
@@ -214,13 +213,13 @@ const recalc = {inst
if inst.mon > 2
- m = (inst.mon - 3) castto(std.time)
- y = inst.year castto(std.time)
+ m = (inst.mon - 3 : std.time)
+ y = (inst.year : std.time)
else
- m = (inst.mon + 9) castto(std.time)
- y = (inst.year - 1) castto(std.time)
+ m = (inst.mon + 9 : std.time)
+ y = (inst.year - 1 : std.time)
;;
- d = inst.day castto(std.time)
+ d = (inst.day : std.time)
c = y / 100
ya = y - 100 * c
@@ -229,10 +228,10 @@ const recalc = {inst
(153 * m + 2)/5 + d - \
719469
tm = j * DayUsec
- tm += (inst.h castto(std.time)) * 3600*1_000_000
- tm += (inst.m castto(std.time)) * 60*1_000_000
- tm += (inst.s castto(std.time)) * 1_000_000
- tm += (inst.us castto(std.time))
+ tm += (inst.h : std.time) * 3600*1_000_000
+ tm += (inst.m : std.time) * 60*1_000_000
+ tm += (inst.s : std.time) * 1_000_000
+ tm += (inst.us : std.time)
-> tm
}
diff --git a/lib/date/fmt.myr b/lib/date/fmt.myr
index e57b6b6..bc57500 100644
--- a/lib/date/fmt.myr
+++ b/lib/date/fmt.myr
@@ -40,9 +40,9 @@ const sbfmt = {sb, ap, opts
const datefmt = {sb, fmt, d
var c
while fmt.len != 0
- (c, fmt) = std.striter(fmt)
+ (c, fmt) = std.strstep(fmt)
if c == '%'
- (c, fmt) = std.striter(fmt)
+ (c, fmt) = std.strstep(fmt)
match c
| 'a': std.sbfmt(sb, "{}", _names.abbrevday[d.day])
| 'A': std.sbfmt(sb, "{}", _names.fullday[d.day])
diff --git a/lib/date/parse.myr b/lib/date/parse.myr
index d33f2fe..36eb479 100644
--- a/lib/date/parse.myr
+++ b/lib/date/parse.myr
@@ -51,7 +51,7 @@ const strparse = {f, s, tz, replace
s = filldate(&d, f, s, seen, &err)
std.bsfree(seen)
- d.actual -= d.tzoff castto(std.time)
+ d.actual -= (d.tzoff : std.time)
match err
| `std.Some e: -> `std.Fail e
| `std.None: /* no error, we're ok */
@@ -70,9 +70,9 @@ const filldate = {d, f, s, seen, err
z = ""
am = `std.None
while f.len != 0
- (fc, f) = std.striter(f)
+ (fc, f) = std.strstep(f)
if fc == '%'
- (fc, f) = std.striter(f)
+ (fc, f) = std.strstep(f)
if std.bshas(seen, fc)
err# = `std.Some `Doublefmt fc
-> s
@@ -80,10 +80,10 @@ const filldate = {d, f, s, seen, err
std.bsput(seen, fc)
match fc
/* named things */
- | 'a': s = indexof(&d.day, s, _names.abbrevday, err)
- | 'A': s = indexof(&d.day, s, _names.fullday, err)
- | 'b': s = indexof(&d.mon, s, _names.abbrevmon, err)
- | 'B': s = indexof(&d.mon, s, _names.fullmon, err)
+ | 'a': s = indexof(&d.day, s, _names.abbrevday[:], err)
+ | 'A': s = indexof(&d.day, s, _names.fullday[:], err)
+ | 'b': s = indexof(&d.mon, s, _names.abbrevmon[:], err)
+ | 'B': s = indexof(&d.mon, s, _names.fullmon[:], err)
| 'c': s = filldate(d, "%Y-%m-%d", s, seen, err)
| 'C':
s = intval(&d.year, s, 2, 2, err)
@@ -92,7 +92,7 @@ const filldate = {d, f, s, seen, err
| 'D': s = filldate(d, "%m/%d/%y", s, seen, err)
| 'e': s = intval(&d.day, s, 1, 2, err)
| 'F': s = filldate(d, "%y-%m-%d", s, seen, err)
- | 'h': s = indexof(&d.day, s, _names.abbrevmon, err)
+ | 'h': s = indexof(&d.day, s, _names.abbrevmon[:], err)
| 'H': s = intval(&d.h, s, 1, 2, err)
| 'I': s = intval(&d.h, s, 1, 2, err)
| 'k': s = intval(&d.h, s, 1, 2, err)
@@ -120,7 +120,7 @@ const filldate = {d, f, s, seen, err
| _: std.fatal("unknown format character %c\n", fc)
;;
else
- (sc, s) = std.striter(s)
+ (sc, s) = std.strstep(s)
if std.isspace(fc) && std.isspace(sc)
s = eatspace(s)
elif sc != fc
@@ -157,7 +157,7 @@ const eatspace = {s
var c
while std.isspace(std.decode(s))
- (c, s) = std.striter(s)
+ (c, s) = std.strstep(s)
;;
-> s
}
@@ -198,6 +198,7 @@ const tzoffset = {dst, s, err
const tzstring = {d, s, err
var c, n
+ n = 0
while true
c = std.decode(s[n:])
if c != '/' && !std.isalnum(c)
@@ -245,7 +246,7 @@ generic intval = {dst : @a::(numeric,integral)#, s : byte[:], \
num = s
for i = 0; i < min; i++
- (c, s) = std.striter(s)
+ (c, s) = std.strstep(s)
if !std.isdigit(c)
err# = `std.Some `Shortint
-> s
diff --git a/lib/date/zoneinfo+posixy.myr b/lib/date/zoneinfo+posixy.myr
index de6eeb4..96b95ff 100644
--- a/lib/date/zoneinfo+posixy.myr
+++ b/lib/date/zoneinfo+posixy.myr
@@ -46,6 +46,7 @@ const findtzoff = {tz, tm -> std.option(date.duration)
elif std.sleq(tz, "local")
path = std.sldup("/etc/localtime")
else
+ path = ""
for z in zonepath
path = std.pathcat(z, tz)
if sys.stat(path, &sb) == 0
@@ -61,7 +62,7 @@ const findtzoff = {tz, tm -> std.option(date.duration)
std.slfree(path)
/* find applicable gmt offset */
- cur = (tm / 1_000_000) castto(int32)
+ cur = (tm / 1_000_000 : int32)
if zone.time.len == 0
-> `std.None
;;
@@ -70,7 +71,7 @@ const findtzoff = {tz, tm -> std.option(date.duration)
;;
ds = zone.ttinfo[zone.timetype[i]].gmtoff
free(zone)
- -> `std.Some (ds castto(date.duration)) * 1_000_000
+ -> `std.Some (ds : date.duration) * 1_000_000
}
const load = {file
@@ -100,38 +101,38 @@ const load = {file
f = std.alloc()
- f.time = std.slalloc(ntime castto(std.size))
+ f.time = std.slalloc((ntime : std.size))
for i = 0; i < ntime; i++
(f.time[i], p) = fetchbe32(p)
;;
- f.timetype = std.slalloc(ntime castto(std.size))
+ f.timetype = std.slalloc((ntime : std.size))
for i = 0; i < ntime; i++
(f.timetype[i], p) = fetchbe8(p)
;;
- f.ttinfo = std.slalloc(ntype castto(std.size))
+ f.ttinfo = std.slalloc((ntype : std.size))
for i = 0; i < ntype; i++
p = fetchttinfo(p, &f.ttinfo[i])
;;
- f.abbrev = std.slalloc(nchar castto(std.size))
+ f.abbrev = std.slalloc((nchar : std.size))
for i = 0; i < nchar; i++
(f.abbrev[i], p) = fetchbe8(p)
;;
- f.leap = std.slalloc(nleap castto(std.size))
+ f.leap = std.slalloc((nleap : std.size))
for i = 0; i < nleap; i++
(f.leap[i][0], p) = fetchbe32(p)
(f.leap[i][1], p) = fetchbe32(p)
;;
- f.isstd = std.slalloc(nisstd castto(std.size))
+ f.isstd = std.slalloc((nisstd : std.size))
for i = 0; i < nisstd; i++
(f.isstd[i], p) = fetchbe8(p)
;;
- f.isgmt = std.slalloc(nisgmt castto(std.size))
+ f.isgmt = std.slalloc((nisgmt : std.size))
for i = 0; i < nisgmt; i++
(f.isgmt[i], p) = fetchbe8(p)
;;
@@ -154,10 +155,7 @@ const fetchbe32 = {sl
var v
std.assert(sl.len >= 4, "Slice too small to fetch int32 from")
- v = (sl[0] castto(int32)) << 24 | \
- (sl[1] castto(int32)) << 16 | \
- (sl[2] castto(int32)) << 8 | \
- (sl[3] castto(int32)) << 0
+ v = std.getbe32(sl[:4])
-> (v, sl[4:])
}