Mercurial > prosody-hg
annotate 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 |
| parents | ff8e122526f4 |
| children | 4c1d3f817063 |
| rev | line source |
|---|---|
| 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 () | |
|
12628
b95da9a593be
util.datetime: Fix argument order in tests
Kim Alvefur <zash@zash.se>
parents:
8392
diff
changeset
|
19 assert.equals("2006-01-02", date(1136239445)); |
| 8392 | 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 () | |
|
12628
b95da9a593be
util.datetime: Fix argument order in tests
Kim Alvefur <zash@zash.se>
parents:
8392
diff
changeset
|
35 assert.equals("22:04:05", time(1136239445)); |
| 8392 | 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 () | |
|
12628
b95da9a593be
util.datetime: Fix argument order in tests
Kim Alvefur <zash@zash.se>
parents:
8392
diff
changeset
|
51 assert.equals("2006-01-02T22:04:05Z", datetime(1136239445)); |
| 8392 | 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 | |
|
12628
b95da9a593be
util.datetime: Fix argument order in tests
Kim Alvefur <zash@zash.se>
parents:
8392
diff
changeset
|
67 assert.equals(1511114293, parse("2017-11-19T17:58:13Z")); |
|
b95da9a593be
util.datetime: Fix argument order in tests
Kim Alvefur <zash@zash.se>
parents:
8392
diff
changeset
|
68 assert.equals(1511114330, parse("2017-11-19T18:58:50+0100")); |
|
b95da9a593be
util.datetime: Fix argument order in tests
Kim Alvefur <zash@zash.se>
parents:
8392
diff
changeset
|
69 assert.equals(1136239445, parse("2006-01-02T15:04:05-0700")); |
| 8392 | 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); |
