| author | |
| committer | |
| log | b9a93152af3ba73e5f681f73a67f0d676e2ad433 |
| tree | 841d836cfd9afc659ebfe2a879a761a8d640802e |
| parent | 2836d9ba610576cecebefd2c780ad1b1204a4b5a |
3 files changed, 161 insertions(+), 161 deletions(-)
build.zig+1-1| ... | @@ -7,7 +7,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -7,7 +7,7 @@ pub fn build(b: *std.Build) void { |
| 7 | const disable_llvm = b.option(bool, "disable_llvm", "use the non-llvm zig codegen") orelse false; | 7 | const disable_llvm = b.option(bool, "disable_llvm", "use the non-llvm zig codegen") orelse false; |
| 8 | 8 | ||
| 9 | const t = b.addTest(.{ | 9 | const t = b.addTest(.{ |
| 10 | .root_source_file = b.path("main.zig"), | 10 | .root_source_file = b.path("test.zig"), |
| 11 | .target = target, | 11 | .target = target, |
| 12 | .optimize = mode, | 12 | .optimize = mode, |
| 13 | }); | 13 | }); |
main.zig deleted-160| ... | @@ -1,160 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const string = []const u8; | ||
| 3 | const time = @import("time"); | ||
| 4 | |||
| 5 | pub fn main() !void { | ||
| 6 | std.log.info("All your codebase are belong to us.", .{}); | ||
| 7 | } | ||
| 8 | |||
| 9 | fn harness(comptime seed: u64, comptime expects: []const [2]string) void { | ||
| 10 | for (0..expects.len) |i| { | ||
| 11 | _ = Case(seed, expects[i][0], expects[i][1]); | ||
| 12 | } | ||
| 13 | } | ||
| 14 | |||
| 15 | fn Case(comptime seed: u64, comptime fmt: string, comptime expected: string) type { | ||
| 16 | return struct { | ||
| 17 | test { | ||
| 18 | const alloc = std.testing.allocator; | ||
| 19 | const instant = time.DateTime.initUnixMs(seed); | ||
| 20 | const actual = try instant.formatAlloc(alloc, fmt); | ||
| 21 | defer alloc.free(actual); | ||
| 22 | std.testing.expectEqualStrings(expected, actual) catch return error.SkipZigTest; | ||
| 23 | } | ||
| 24 | }; | ||
| 25 | } | ||
| 26 | |||
| 27 | fn expectFmt(instant: time.DateTime, comptime fmt: string, comptime expected: string) !void { | ||
| 28 | const alloc = std.testing.allocator; | ||
| 29 | const actual = try instant.formatAlloc(alloc, fmt); | ||
| 30 | defer alloc.free(actual); | ||
| 31 | std.testing.expectEqualStrings(expected, actual) catch return error.SkipZigTest; | ||
| 32 | } | ||
| 33 | |||
| 34 | comptime { | ||
| 35 | harness(0, &.{.{ "YYYY-MM-DD HH:mm:ss", "1970-01-01 00:00:00" }}); | ||
| 36 | harness(1257894000000, &.{.{ "YYYY-MM-DD HH:mm:ss", "2009-11-10 23:00:00" }}); | ||
| 37 | harness(1634858430000, &.{.{ "YYYY-MM-DD HH:mm:ss", "2021-10-21 23:20:30" }}); | ||
| 38 | harness(1634858430023, &.{.{ "YYYY-MM-DD HH:mm:ss.SSS", "2021-10-21 23:20:30.023" }}); | ||
| 39 | harness(1144509852789, &.{.{ "YYYY-MM-DD HH:mm:ss.SSS", "2006-04-08 15:24:12.789" }}); | ||
| 40 | |||
| 41 | harness(1635033600000, &.{ | ||
| 42 | .{ "H", "0" }, .{ "HH", "00" }, | ||
| 43 | .{ "h", "12" }, .{ "hh", "12" }, | ||
| 44 | .{ "k", "24" }, .{ "kk", "24" }, | ||
| 45 | }); | ||
| 46 | |||
| 47 | harness(1635037200000, &.{ | ||
| 48 | .{ "H", "1" }, .{ "HH", "01" }, | ||
| 49 | .{ "h", "1" }, .{ "hh", "01" }, | ||
| 50 | .{ "k", "1" }, .{ "kk", "01" }, | ||
| 51 | }); | ||
| 52 | |||
| 53 | harness(1635076800000, &.{ | ||
| 54 | .{ "H", "12" }, .{ "HH", "12" }, | ||
| 55 | .{ "h", "12" }, .{ "hh", "12" }, | ||
| 56 | .{ "k", "12" }, .{ "kk", "12" }, | ||
| 57 | }); | ||
| 58 | harness(1635080400000, &.{ | ||
| 59 | .{ "H", "13" }, .{ "HH", "13" }, | ||
| 60 | .{ "h", "1" }, .{ "hh", "01" }, | ||
| 61 | .{ "k", "13" }, .{ "kk", "13" }, | ||
| 62 | }); | ||
| 63 | |||
| 64 | harness(1144509852789, &.{ | ||
| 65 | .{ "M", "4" }, | ||
| 66 | .{ "Mo", "4th" }, | ||
| 67 | .{ "MM", "04" }, | ||
| 68 | .{ "MMM", "Apr" }, | ||
| 69 | .{ "MMMM", "April" }, | ||
| 70 | |||
| 71 | .{ "Q", "2" }, | ||
| 72 | .{ "Qo", "2nd" }, | ||
| 73 | |||
| 74 | .{ "D", "8" }, | ||
| 75 | .{ "Do", "8th" }, | ||
| 76 | .{ "DD", "08" }, | ||
| 77 | |||
| 78 | .{ "DDD", "98" }, | ||
| 79 | .{ "DDDo", "98th" }, | ||
| 80 | .{ "DDDD", "098" }, | ||
| 81 | |||
| 82 | .{ "d", "6" }, | ||
| 83 | .{ "do", "6th" }, | ||
| 84 | .{ "dd", "Sa" }, | ||
| 85 | .{ "ddd", "Sat" }, | ||
| 86 | .{ "dddd", "Saturday" }, | ||
| 87 | .{ "e", "6" }, | ||
| 88 | .{ "E", "7" }, | ||
| 89 | |||
| 90 | .{ "w", "14" }, | ||
| 91 | .{ "wo", "14th" }, | ||
| 92 | .{ "ww", "14" }, | ||
| 93 | |||
| 94 | .{ "Y", "12006" }, | ||
| 95 | .{ "YY", "06" }, | ||
| 96 | .{ "YYY", "2006" }, | ||
| 97 | .{ "YYYY", "2006" }, | ||
| 98 | |||
| 99 | .{ "N", "AD" }, | ||
| 100 | .{ "NN", "Anno Domini" }, | ||
| 101 | |||
| 102 | .{ "A", "PM" }, | ||
| 103 | .{ "a", "pm" }, | ||
| 104 | |||
| 105 | .{ "H", "15" }, | ||
| 106 | .{ "HH", "15" }, | ||
| 107 | .{ "h", "3" }, | ||
| 108 | .{ "hh", "03" }, | ||
| 109 | .{ "k", "15" }, | ||
| 110 | .{ "kk", "15" }, | ||
| 111 | |||
| 112 | .{ "m", "24" }, | ||
| 113 | .{ "mm", "24" }, | ||
| 114 | |||
| 115 | .{ "s", "12" }, | ||
| 116 | .{ "ss", "12" }, | ||
| 117 | |||
| 118 | .{ "S", "7" }, | ||
| 119 | .{ "SS", "78" }, | ||
| 120 | .{ "SSS", "789" }, | ||
| 121 | |||
| 122 | .{ "z", "UTC" }, | ||
| 123 | .{ "Z", "+00:00" }, | ||
| 124 | .{ "ZZ", "+0000" }, | ||
| 125 | |||
| 126 | .{ "x", "1144509852789" }, | ||
| 127 | .{ "X", "1144509852" }, | ||
| 128 | |||
| 129 | .{ time.format.LT, "3:24 PM" }, | ||
| 130 | |||
| 131 | .{ time.format.LTS, "3:24:12 PM" }, | ||
| 132 | |||
| 133 | .{ time.format.L, "04/08/2006" }, | ||
| 134 | |||
| 135 | .{ time.format.l, "4/8/2006" }, | ||
| 136 | |||
| 137 | .{ time.format.LL, "April 8, 2006" }, | ||
| 138 | |||
| 139 | .{ time.format.ll, "Apr 8, 2006" }, | ||
| 140 | |||
| 141 | .{ time.format.LLL, "April 8, 2006 3:24 PM" }, | ||
| 142 | |||
| 143 | .{ time.format.lll, "Apr 8, 2006 3:24 PM" }, | ||
| 144 | |||
| 145 | .{ time.format.LLLL, "Saturday, April 8, 2006 3:24 PM" }, | ||
| 146 | |||
| 147 | .{ time.format.llll, "Sat, Apr 8, 2006 3:24 PM" }, | ||
| 148 | }); | ||
| 149 | |||
| 150 | // https://github.com/nektro/zig-time/issues/3 | ||
| 151 | harness(1144509852789, &.{.{ "YYYYMM", "200604" }}); | ||
| 152 | } | ||
| 153 | |||
| 154 | // https://github.com/nektro/zig-time/issues/9 | ||
| 155 | test { | ||
| 156 | var t = time.DateTime.initUnix(1330502962); | ||
| 157 | try expectFmt(t, "YYYY-MM-DD hh:mm:ss A z", "2012-02-29 08:09:22 AM UTC"); | ||
| 158 | t = t.addYears(1); | ||
| 159 | try expectFmt(t, "YYYY-MM-DD hh:mm:ss A z", "2013-03-01 08:09:22 AM UTC"); | ||
| 160 | } | ||
test.zig created+160| ... | @@ -0,0 +1,160 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const string = []const u8; | ||
| 3 | const time = @import("time"); | ||
| 4 | |||
| 5 | pub fn main() !void { | ||
| 6 | std.log.info("All your codebase are belong to us.", .{}); | ||
| 7 | } | ||
| 8 | |||
| 9 | fn harness(comptime seed: u64, comptime expects: []const [2]string) void { | ||
| 10 | for (0..expects.len) |i| { | ||
| 11 | _ = Case(seed, expects[i][0], expects[i][1]); | ||
| 12 | } | ||
| 13 | } | ||
| 14 | |||
| 15 | fn Case(comptime seed: u64, comptime fmt: string, comptime expected: string) type { | ||
| 16 | return struct { | ||
| 17 | test { | ||
| 18 | const alloc = std.testing.allocator; | ||
| 19 | const instant = time.DateTime.initUnixMs(seed); | ||
| 20 | const actual = try instant.formatAlloc(alloc, fmt); | ||
| 21 | defer alloc.free(actual); | ||
| 22 | std.testing.expectEqualStrings(expected, actual) catch return error.SkipZigTest; | ||
| 23 | } | ||
| 24 | }; | ||
| 25 | } | ||
| 26 | |||
| 27 | fn expectFmt(instant: time.DateTime, comptime fmt: string, comptime expected: string) !void { | ||
| 28 | const alloc = std.testing.allocator; | ||
| 29 | const actual = try instant.formatAlloc(alloc, fmt); | ||
| 30 | defer alloc.free(actual); | ||
| 31 | std.testing.expectEqualStrings(expected, actual) catch return error.SkipZigTest; | ||
| 32 | } | ||
| 33 | |||
| 34 | comptime { | ||
| 35 | harness(0, &.{.{ "YYYY-MM-DD HH:mm:ss", "1970-01-01 00:00:00" }}); | ||
| 36 | harness(1257894000000, &.{.{ "YYYY-MM-DD HH:mm:ss", "2009-11-10 23:00:00" }}); | ||
| 37 | harness(1634858430000, &.{.{ "YYYY-MM-DD HH:mm:ss", "2021-10-21 23:20:30" }}); | ||
| 38 | harness(1634858430023, &.{.{ "YYYY-MM-DD HH:mm:ss.SSS", "2021-10-21 23:20:30.023" }}); | ||
| 39 | harness(1144509852789, &.{.{ "YYYY-MM-DD HH:mm:ss.SSS", "2006-04-08 15:24:12.789" }}); | ||
| 40 | |||
| 41 | harness(1635033600000, &.{ | ||
| 42 | .{ "H", "0" }, .{ "HH", "00" }, | ||
| 43 | .{ "h", "12" }, .{ "hh", "12" }, | ||
| 44 | .{ "k", "24" }, .{ "kk", "24" }, | ||
| 45 | }); | ||
| 46 | |||
| 47 | harness(1635037200000, &.{ | ||
| 48 | .{ "H", "1" }, .{ "HH", "01" }, | ||
| 49 | .{ "h", "1" }, .{ "hh", "01" }, | ||
| 50 | .{ "k", "1" }, .{ "kk", "01" }, | ||
| 51 | }); | ||
| 52 | |||
| 53 | harness(1635076800000, &.{ | ||
| 54 | .{ "H", "12" }, .{ "HH", "12" }, | ||
| 55 | .{ "h", "12" }, .{ "hh", "12" }, | ||
| 56 | .{ "k", "12" }, .{ "kk", "12" }, | ||
| 57 | }); | ||
| 58 | harness(1635080400000, &.{ | ||
| 59 | .{ "H", "13" }, .{ "HH", "13" }, | ||
| 60 | .{ "h", "1" }, .{ "hh", "01" }, | ||
| 61 | .{ "k", "13" }, .{ "kk", "13" }, | ||
| 62 | }); | ||
| 63 | |||
| 64 | harness(1144509852789, &.{ | ||
| 65 | .{ "M", "4" }, | ||
| 66 | .{ "Mo", "4th" }, | ||
| 67 | .{ "MM", "04" }, | ||
| 68 | .{ "MMM", "Apr" }, | ||
| 69 | .{ "MMMM", "April" }, | ||
| 70 | |||
| 71 | .{ "Q", "2" }, | ||
| 72 | .{ "Qo", "2nd" }, | ||
| 73 | |||
| 74 | .{ "D", "8" }, | ||
| 75 | .{ "Do", "8th" }, | ||
| 76 | .{ "DD", "08" }, | ||
| 77 | |||
| 78 | .{ "DDD", "98" }, | ||
| 79 | .{ "DDDo", "98th" }, | ||
| 80 | .{ "DDDD", "098" }, | ||
| 81 | |||
| 82 | .{ "d", "6" }, | ||
| 83 | .{ "do", "6th" }, | ||
| 84 | .{ "dd", "Sa" }, | ||
| 85 | .{ "ddd", "Sat" }, | ||
| 86 | .{ "dddd", "Saturday" }, | ||
| 87 | .{ "e", "6" }, | ||
| 88 | .{ "E", "7" }, | ||
| 89 | |||
| 90 | .{ "w", "14" }, | ||
| 91 | .{ "wo", "14th" }, | ||
| 92 | .{ "ww", "14" }, | ||
| 93 | |||
| 94 | .{ "Y", "12006" }, | ||
| 95 | .{ "YY", "06" }, | ||
| 96 | .{ "YYY", "2006" }, | ||
| 97 | .{ "YYYY", "2006" }, | ||
| 98 | |||
| 99 | .{ "N", "AD" }, | ||
| 100 | .{ "NN", "Anno Domini" }, | ||
| 101 | |||
| 102 | .{ "A", "PM" }, | ||
| 103 | .{ "a", "pm" }, | ||
| 104 | |||
| 105 | .{ "H", "15" }, | ||
| 106 | .{ "HH", "15" }, | ||
| 107 | .{ "h", "3" }, | ||
| 108 | .{ "hh", "03" }, | ||
| 109 | .{ "k", "15" }, | ||
| 110 | .{ "kk", "15" }, | ||
| 111 | |||
| 112 | .{ "m", "24" }, | ||
| 113 | .{ "mm", "24" }, | ||
| 114 | |||
| 115 | .{ "s", "12" }, | ||
| 116 | .{ "ss", "12" }, | ||
| 117 | |||
| 118 | .{ "S", "7" }, | ||
| 119 | .{ "SS", "78" }, | ||
| 120 | .{ "SSS", "789" }, | ||
| 121 | |||
| 122 | .{ "z", "UTC" }, | ||
| 123 | .{ "Z", "+00:00" }, | ||
| 124 | .{ "ZZ", "+0000" }, | ||
| 125 | |||
| 126 | .{ "x", "1144509852789" }, | ||
| 127 | .{ "X", "1144509852" }, | ||
| 128 | |||
| 129 | .{ time.format.LT, "3:24 PM" }, | ||
| 130 | |||
| 131 | .{ time.format.LTS, "3:24:12 PM" }, | ||
| 132 | |||
| 133 | .{ time.format.L, "04/08/2006" }, | ||
| 134 | |||
| 135 | .{ time.format.l, "4/8/2006" }, | ||
| 136 | |||
| 137 | .{ time.format.LL, "April 8, 2006" }, | ||
| 138 | |||
| 139 | .{ time.format.ll, "Apr 8, 2006" }, | ||
| 140 | |||
| 141 | .{ time.format.LLL, "April 8, 2006 3:24 PM" }, | ||
| 142 | |||
| 143 | .{ time.format.lll, "Apr 8, 2006 3:24 PM" }, | ||
| 144 | |||
| 145 | .{ time.format.LLLL, "Saturday, April 8, 2006 3:24 PM" }, | ||
| 146 | |||
| 147 | .{ time.format.llll, "Sat, Apr 8, 2006 3:24 PM" }, | ||
| 148 | }); | ||
| 149 | |||
| 150 | // https://github.com/nektro/zig-time/issues/3 | ||
| 151 | harness(1144509852789, &.{.{ "YYYYMM", "200604" }}); | ||
| 152 | } | ||
| 153 | |||
| 154 | // https://github.com/nektro/zig-time/issues/9 | ||
| 155 | test { | ||
| 156 | var t = time.DateTime.initUnix(1330502962); | ||
| 157 | try expectFmt(t, "YYYY-MM-DD hh:mm:ss A z", "2012-02-29 08:09:22 AM UTC"); | ||
| 158 | t = t.addYears(1); | ||
| 159 | try expectFmt(t, "YYYY-MM-DD hh:mm:ss A z", "2013-03-01 08:09:22 AM UTC"); | ||
| 160 | } | ||