summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorS. Gilles <sgilles@math.umd.edu>2017-09-22 18:55:46 -0400
committerOri Bernstein <ori@mmarkovcorp.com>2017-09-26 11:05:21 -0700
commit7dc5e79e0e08453f3e57bb67010fa524d265225a (patch)
treea936c6221e718ec8b705b080dbe76c4001feb393
parent61fc99f4d1bb75a6ac88cf5395f37f735589b4ce (diff)
downloadmc-7dc5e79e0e08453f3e57bb67010fa524d265225a.tar.gz
Match date abbreviations in the middle of formats
-rw-r--r--lib/date/parse.myr4
-rw-r--r--lib/date/test/parse.myr9
2 files changed, 11 insertions, 2 deletions
diff --git a/lib/date/parse.myr b/lib/date/parse.myr
index 80f0b76..19798dd 100644
--- a/lib/date/parse.myr
+++ b/lib/date/parse.myr
@@ -164,9 +164,9 @@ const eatspace = {s
const indexof = {dst, s, set, err
for var i = 0; i < set.len; i++
- if s.len >= set[i].len && std.streq(s, set[i])
+ if s.len >= set[i].len && std.streq(s[:set[i].len], set[i])
dst# = i
- -> s
+ -> s[set[i].len:]
;;
;;
err# = `std.Some `Badname s
diff --git a/lib/date/test/parse.myr b/lib/date/test/parse.myr
index 6bc7347..a6aef7e 100644
--- a/lib/date/test/parse.myr
+++ b/lib/date/test/parse.myr
@@ -37,6 +37,15 @@ const main = {
| `std.Err m:
std.fatal("Failed to parse date: {}", m)
;;
+
+ /*Names*/
+ match date.parsefmt("%a, %d %b %Y %H:%M:%S %z", "Thu, 21 Sep 2017 13:55:05 -0400")
+ | `std.Ok d:
+ std.assert(d.actual == 1506016505 * 1_000_000, "wrong timestamp")
+ eq(std.bfmt(buf[:], "{D}", d), "2017-9-21 13:55:05 -0400")
+ | `std.Err m:
+ std.fatal("Failed to parse date: {}", m)
+ ;;
}
const eq = {actual, expected