8392
|
1 local util_datetime = require "util.datetime";
|
|
2
|
|
3 describe("util.datetime", function ()
|
|
4 it("should have been loaded", function ()
|
|
5 assert.is_table(util_datetime);
|
|
6 end);
|
|
7 describe("#date", function ()
|
|
8 local date = util_datetime.date;
|
|
9 it("should exist", function ()
|
|
10 assert.is_function(date);
|
|
11 end);
|
|
12 it("should return a string", function ()
|
|
13 assert.is_string(date());
|
|
14 end);
|
|
15 it("should look like a date", function ()
|
|
16 assert.truthy(string.find(date(), "^%d%d%d%d%-%d%d%-%d%d$"));
|
|
17 end);
|
|
18 it("should work", function ()
|
|
19 assert.equals(date(1136239445), "2006-01-02");
|
|
20 end);
|
|
21 end);
|
|
22 describe("#time", function ()
|
|
23 local time = util_datetime.time;
|
|
24 it("should exist", function ()
|
|
25 assert.is_function(time);
|
|
26 end);
|
|
27 it("should return a string", function ()
|
|
28 assert.is_string(time());
|
|
29 end);
|
|
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"));
|
|
33 end);
|
|
34 it("should work", function ()
|
|
35 assert.equals(time(1136239445), "22:04:05");
|
|
36 end);
|
|
37 end);
|
|
38 describe("#datetime", function ()
|
|
39 local datetime = util_datetime.datetime;
|
|
40 it("should exist", function ()
|
|
41 assert.is_function(datetime);
|
|
42 end);
|
|
43 it("should return a string", function ()
|
|
44 assert.is_string(datetime());
|
|
45 end);
|
|
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"));
|
|
49 end);
|
|
50 it("should work", function ()
|
|
51 assert.equals(datetime(1136239445), "2006-01-02T22:04:05Z");
|
|
52 end);
|
|
53 end);
|
|
54 describe("#legacy", function ()
|
|
55 local legacy = util_datetime.legacy;
|
|
56 it("should exist", function ()
|
|
57 assert.is_function(legacy);
|
|
58 end);
|
|
59 end);
|
|
60 describe("#parse", function ()
|
|
61 local parse = util_datetime.parse;
|
|
62 it("should exist", function ()
|
|
63 assert.is_function(parse);
|
|
64 end);
|
|
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);
|
|
70 end);
|
|
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"));
|
|
74 end);
|
|
75 end);
|
|
76 end);
|