diff options
Diffstat (limited to 'tests/stdlib/ttimes.nim')
-rw-r--r-- | tests/stdlib/ttimes.nim | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/stdlib/ttimes.nim b/tests/stdlib/ttimes.nim index b29f5090b..ef6712171 100644 --- a/tests/stdlib/ttimes.nim +++ b/tests/stdlib/ttimes.nim @@ -452,6 +452,23 @@ suite "ttimes": doAssert dt.format("zz") == tz[2] doAssert dt.format("zzz") == tz[3] + test "format locale": + let loc = DateTimeLocale( + MMM: ["Fir","Sec","Thi","Fou","Fif","Six","Sev","Eig","Nin","Ten","Ele","Twe"], + MMMM: ["Firsty", "Secondy", "Thirdy", "Fourthy", "Fifthy", "Sixthy", "Seventhy", "Eighthy", "Ninthy", "Tenthy", "Eleventhy", "Twelfthy"], + ddd: ["Red", "Ora.", "Yel.", "Gre.", "Blu.", "Vio.", "Whi."], + dddd: ["Red", "Orange", "Yellow", "Green", "Blue", "Violet", "White"], + ) + var dt = initDateTime(5, mJan, 2010, 17, 01, 02, utc()) + check dt.format("d", loc) == "5" + check dt.format("dd", loc) == "05" + check dt.format("ddd", loc) == "Ora." + check dt.format("dddd", loc) == "Orange" + check dt.format("M", loc) == "1" + check dt.format("MM", loc) == "01" + check dt.format("MMM", loc) == "Fir" + check dt.format("MMMM", loc) == "Firsty" + test "parse": check $parse("20180101", "yyyyMMdd", utc()) == "2018-01-01T00:00:00Z" parseTestExcp("+120180101", "yyyyMMdd") @@ -473,6 +490,16 @@ suite "ttimes": parseTestExcp("2000 A", "yyyy g") + test "parse locale": + let loc = DateTimeLocale( + MMM: ["Fir","Sec","Thi","Fou","Fif","Six","Sev","Eig","Nin","Ten","Ele","Twe"], + MMMM: ["Firsty", "Secondy", "Thirdy", "Fourthy", "Fifthy", "Sixthy", "Seventhy", "Eighthy", "Ninthy", "Tenthy", "Eleventhy", "Twelfthy"], + ddd: ["Red", "Ora.", "Yel.", "Gre.", "Blu.", "Vio.", "Whi."], + dddd: ["Red", "Orange", "Yellow", "Green", "Blue", "Violet", "White"], + ) + check $parse("02 Fir 2019", "dd MMM yyyy", utc(), loc) == "2019-01-02T00:00:00Z" + check $parse("Fourthy 6, 2017", "MMMM d, yyyy", utc(), loc) == "2017-04-06T00:00:00Z" + test "countLeapYears": # 1920, 2004 and 2020 are leap years, and should be counted starting at the following year check countLeapYears(1920) + 1 == countLeapYears(1921) |