Software /
code /
prosody
Comparison
spec/util_datetime_spec.lua @ 12628:b95da9a593be
util.datetime: Fix argument order in tests
The expected value goes first.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 14 Aug 2022 16:51:10 +0200 |
parent | 8392:ff8e122526f4 |
child | 12629:4c1d3f817063 |
comparison
equal
deleted
inserted
replaced
12627:b8ce0f61855b | 12628:b95da9a593be |
---|---|
14 end); | 14 end); |
15 it("should look like a date", function () | 15 it("should look like a date", function () |
16 assert.truthy(string.find(date(), "^%d%d%d%d%-%d%d%-%d%d$")); | 16 assert.truthy(string.find(date(), "^%d%d%d%d%-%d%d%-%d%d$")); |
17 end); | 17 end); |
18 it("should work", function () | 18 it("should work", function () |
19 assert.equals(date(1136239445), "2006-01-02"); | 19 assert.equals("2006-01-02", date(1136239445)); |
20 end); | 20 end); |
21 end); | 21 end); |
22 describe("#time", function () | 22 describe("#time", function () |
23 local time = util_datetime.time; | 23 local time = util_datetime.time; |
24 it("should exist", function () | 24 it("should exist", function () |
30 it("should look like a timestamp", function () | 30 it("should look like a timestamp", function () |
31 -- Note: Sub-second precision and timezones are ignored | 31 -- Note: Sub-second precision and timezones are ignored |
32 assert.truthy(string.find(time(), "^%d%d:%d%d:%d%d")); | 32 assert.truthy(string.find(time(), "^%d%d:%d%d:%d%d")); |
33 end); | 33 end); |
34 it("should work", function () | 34 it("should work", function () |
35 assert.equals(time(1136239445), "22:04:05"); | 35 assert.equals("22:04:05", time(1136239445)); |
36 end); | 36 end); |
37 end); | 37 end); |
38 describe("#datetime", function () | 38 describe("#datetime", function () |
39 local datetime = util_datetime.datetime; | 39 local datetime = util_datetime.datetime; |
40 it("should exist", function () | 40 it("should exist", function () |
46 it("should look like a timestamp", function () | 46 it("should look like a timestamp", function () |
47 -- Note: Sub-second precision and timezones are ignored | 47 -- Note: Sub-second precision and timezones are ignored |
48 assert.truthy(string.find(datetime(), "^%d%d%d%d%-%d%d%-%d%dT%d%d:%d%d:%d%d")); | 48 assert.truthy(string.find(datetime(), "^%d%d%d%d%-%d%d%-%d%dT%d%d:%d%d:%d%d")); |
49 end); | 49 end); |
50 it("should work", function () | 50 it("should work", function () |
51 assert.equals(datetime(1136239445), "2006-01-02T22:04:05Z"); | 51 assert.equals("2006-01-02T22:04:05Z", datetime(1136239445)); |
52 end); | 52 end); |
53 end); | 53 end); |
54 describe("#legacy", function () | 54 describe("#legacy", function () |
55 local legacy = util_datetime.legacy; | 55 local legacy = util_datetime.legacy; |
56 it("should exist", function () | 56 it("should exist", function () |
62 it("should exist", function () | 62 it("should exist", function () |
63 assert.is_function(parse); | 63 assert.is_function(parse); |
64 end); | 64 end); |
65 it("should work", function () | 65 it("should work", function () |
66 -- Timestamp used by Go | 66 -- Timestamp used by Go |
67 assert.equals(parse("2017-11-19T17:58:13Z"), 1511114293); | 67 assert.equals(1511114293, parse("2017-11-19T17:58:13Z")); |
68 assert.equals(parse("2017-11-19T18:58:50+0100"), 1511114330); | 68 assert.equals(1511114330, parse("2017-11-19T18:58:50+0100")); |
69 assert.equals(parse("2006-01-02T15:04:05-0700"), 1136239445); | 69 assert.equals(1136239445, parse("2006-01-02T15:04:05-0700")); |
70 end); | 70 end); |
71 it("should handle timezones", function () | 71 it("should handle timezones", function () |
72 -- https://xmpp.org/extensions/xep-0082.html#example-2 and 3 | 72 -- https://xmpp.org/extensions/xep-0082.html#example-2 and 3 |
73 assert.equals(parse("1969-07-21T02:56:15Z"), parse("1969-07-20T21:56:15-05:00")); | 73 assert.equals(parse("1969-07-21T02:56:15Z"), parse("1969-07-20T21:56:15-05:00")); |
74 end); | 74 end); |