1 local util_datetime
= require
"util.datetime";
3 describe("util.datetime", function ()
4 it("should have been loaded", function ()
5 assert.is_table(util_datetime
);
7 describe("#date", function ()
8 local date = util_datetime
.date;
9 it("should exist", function ()
10 assert.is_function(date);
12 it("should return a string", function ()
13 assert.is_string(date());
15 it("should look like a date", function ()
16 assert.truthy(string.find(date(), "^%d%d%d%d%-%d%d%-%d%d$"));
18 it("should work", function ()
19 assert.equals(date(1136239445), "2006-01-02");
22 describe("#time", function ()
23 local time
= util_datetime
.time
;
24 it("should exist", function ()
25 assert.is_function(time
);
27 it("should return a string", function ()
28 assert.is_string(time());
30 it("should look like a timestamp", function ()
31 -- Note: Sub-second precision and timezones are ignored
32 assert.truthy(string.find(time(), "^%d%d:%d%d:%d%d"));
34 it("should work", function ()
35 assert.equals(time(1136239445), "22:04:05");
38 describe("#datetime", function ()
39 local datetime
= util_datetime
.datetime
;
40 it("should exist", function ()
41 assert.is_function(datetime
);
43 it("should return a string", function ()
44 assert.is_string(datetime());
46 it("should look like a timestamp", function ()
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"));
50 it("should work", function ()
51 assert.equals(datetime(1136239445), "2006-01-02T22:04:05Z");
54 describe("#legacy", function ()
55 local legacy
= util_datetime
.legacy
;
56 it("should exist", function ()
57 assert.is_function(legacy
);
60 describe("#parse", function ()
61 local parse
= util_datetime
.parse
;
62 it("should exist", function ()
63 assert.is_function(parse
);
65 it("should work", function ()
66 -- Timestamp used by Go
67 assert.equals(parse("2017-11-19T17:58:13Z"), 1511114293);
68 assert.equals(parse("2017-11-19T18:58:50+0100"), 1511114330);
69 assert.equals(parse("2006-01-02T15:04:05-0700"), 1136239445);
71 it("should handle timezones", function ()
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"));