summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorS. Gilles <sgilles@math.umd.edu>2017-09-24 16:08:47 -0400
committerOri Bernstein <ori@mmarkovcorp.com>2017-09-26 11:05:21 -0700
commitdae26bc67285c9bdc8f6093ada35d7e7ca808796 (patch)
tree077b8232ff7d4230132f39ccd1e486805068c913 /lib
parent7dc5e79e0e08453f3e57bb67010fa524d265225a (diff)
downloadmc-dae26bc67285c9bdc8f6093ada35d7e7ca808796.tar.gz
Left-pad %m and %k output with 0
Diffstat (limited to 'lib')
-rw-r--r--lib/date/fmt.myr4
-rw-r--r--lib/date/test/fmt.myr26
-rw-r--r--lib/date/test/parse.myr4
3 files changed, 17 insertions, 17 deletions
diff --git a/lib/date/fmt.myr b/lib/date/fmt.myr
index c66827b..323b25a 100644
--- a/lib/date/fmt.myr
+++ b/lib/date/fmt.myr
@@ -62,9 +62,9 @@ const datefmt = {sb, fmt, d
| 'H': std.sbfmt(sb, "{p=0,w=2}", d.h)
| 'I': std.sbfmt(sb, "{p=0,w=2}", d.h % 12)
| 'j': std.sbfmt(sb, "year day... unimplemented.")
- | 'k': std.sbfmt(sb, "{}", d.h)
+ | 'k': std.sbfmt(sb, "{p=0,w=2}", d.h)
| 'l': std.sbfmt(sb, "{}", d.h % 12)
- | 'm': std.sbfmt(sb, "{}", d.mon)
+ | 'm': std.sbfmt(sb, "{p=0,w=2}", d.mon)
| 'M': std.sbfmt(sb, "{p=0,w=2}", d.m)
| 'n': std.sbfmt(sb, "\n")
| 'O': std.sbfmt(sb, "unsupported %O")
diff --git a/lib/date/test/fmt.myr b/lib/date/test/fmt.myr
index 024c7b6..d0abba9 100644
--- a/lib/date/test/fmt.myr
+++ b/lib/date/test/fmt.myr
@@ -7,13 +7,13 @@ const main = {
/* epoch */
d = date.mkinstant(0, "")
- eq("1970-1-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d))
+ eq("1970-01-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d))
d = date.mkinstant(24*3600*1_000_000, "")
- eq("1970-1-02 00:00:00 +0000", std.bfmt(buf[:], "{D}", d))
+ eq("1970-01-02 00:00:00 +0000", std.bfmt(buf[:], "{D}", d))
/* epoch + 12 hours */
d = date.mkinstant(12*3600*1_000_000, "")
- eq("1970-1-01 12:00:00 +0000", std.bfmt(buf[:], "{D}", d))
+ eq("1970-01-01 12:00:00 +0000", std.bfmt(buf[:], "{D}", d))
/* epoch - 6 hours */
d = date.mkinstant(-6*3600*1_000_000, "")
@@ -25,11 +25,11 @@ const main = {
/* more or less random: Fri 29 Aug 2014 07:47:43 PM UTC*/
d = date.mkinstant(1_409_341_663*1_000_000, "")
- eq("2014-8-29 19:47:43 +0000", std.bfmt(buf[:], "{D}", d))
+ eq("2014-08-29 19:47:43 +0000", std.bfmt(buf[:], "{D}", d))
/* large negative time stamp */
d = date.mkinstant(-50000000000*1_000_000, "")
- eq("385-7-25 07:06:40 +0000", std.bfmt(buf[:], "{D}", d))
+ eq("385-07-25 07:06:40 +0000", std.bfmt(buf[:], "{D}", d))
/* date : the bc */
d = date.mkinstant(-70000000000*1_000_000, "")
@@ -38,27 +38,27 @@ const main = {
/* test addition and subtraction of dates */
d = date.mkinstant(-1, "")
d = date.addperiod(d, `date.Hour 1)
- eq("1970-1-01 00:59:59 +0000", std.bfmt(buf[:], "{D}", d))
+ eq("1970-01-01 00:59:59 +0000", std.bfmt(buf[:], "{D}", d))
d = date.mkinstant(0, "")
d = date.addperiod(d, `date.Hour 24)
- eq("1970-1-02 00:00:00 +0000", std.bfmt(buf[:], "{D}", d))
+ eq("1970-01-02 00:00:00 +0000", std.bfmt(buf[:], "{D}", d))
d = date.mkinstant(0, "")
d = date.addperiod(d, `date.Day 1)
- eq("1970-1-02 00:00:00 +0000", std.bfmt(buf[:], "{D}", d))
+ eq("1970-01-02 00:00:00 +0000", std.bfmt(buf[:], "{D}", d))
d = date.subperiod(d, `date.Day 1)
- eq("1970-1-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d))
+ eq("1970-01-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d))
d = date.subperiod(d, `date.Year 1)
- eq("1969-1-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d))
+ eq("1969-01-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d))
d = date.addperiod(d, `date.Day 365)
- eq("1970-1-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d))
+ eq("1970-01-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d))
d = date.addperiod(d, `date.Year 2)
- eq("1972-1-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d))
+ eq("1972-01-01 00:00:00 +0000", std.bfmt(buf[:], "{D}", d))
d = date.addperiod(d, `date.Day 365)
eq("1972-12-31 00:00:00 +0000", std.bfmt(buf[:], "{D}", d))
@@ -66,7 +66,7 @@ const main = {
for var i = 0; i < 50; i++
d = date.addperiod(d, `date.Day 1)
d = date.addperiod(d, `date.Second 1)
- s = std.fmt("1970-{}-{p=0,w=2} 12:{p=0,w=2}:{p=0,w=2} +0000", \
+ s = std.fmt("1970-{p=0,w=2}-{p=0,w=2} 12:{p=0,w=2}:{p=0,w=2} +0000", \
(i+1)/31 + 1, (i+1)%31+1, (i+13)/60, (i+13)%60)
eq(s, std.bfmt(buf[:], "{D}", d))
std.slfree(s)
diff --git a/lib/date/test/parse.myr b/lib/date/test/parse.myr
index a6aef7e..dc34707 100644
--- a/lib/date/test/parse.myr
+++ b/lib/date/test/parse.myr
@@ -24,7 +24,7 @@ const main = {
match date.parsefmtz("%Y-%m-%d %H:%M:%S %z", "1969-12-31 16:00:00 -0800", "")
| `std.Ok d:
std.assert(d.actual == 0, "got wrong date")
- eq(std.bfmt(buf[:], "{D}", d), "1970-1-01 00:00:00 +0000")
+ eq(std.bfmt(buf[:], "{D}", d), "1970-01-01 00:00:00 +0000")
| `std.Err m:
std.fatal("failed to parse date: {}\n", m)
;;
@@ -42,7 +42,7 @@ const main = {
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")
+ eq(std.bfmt(buf[:], "{D}", d), "2017-09-21 13:55:05 -0400")
| `std.Err m:
std.fatal("Failed to parse date: {}", m)
;;