shithub: mc

Download patch

ref: 7dc5e79e0e08453f3e57bb67010fa524d265225a
parent: 61fc99f4d1bb75a6ac88cf5395f37f735589b4ce
author: S. Gilles <sgilles@math.umd.edu>
date: Fri Sep 22 14:55:46 EDT 2017

Match date abbreviations in the middle of formats

--- a/lib/date/parse.myr
+++ b/lib/date/parse.myr
@@ -164,9 +164,9 @@
 
 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
--- a/lib/date/test/parse.myr
+++ b/lib/date/test/parse.myr
@@ -37,6 +37,15 @@
 	| `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