chore(tests): fix toUniversalTime test

This commit is contained in:
Erica Marigold 2023-09-07 15:37:10 +05:30
parent ac948b22d9
commit 6ddaecb0ba
No known key found for this signature in database
GPG key ID: 23CD97ABBBCC5ED2

View file

@ -1,24 +1,30 @@
local DateTime = require("@lune/DateTime")
local dateTime = (DateTime.fromIsoDate("2023-08-27T05:54:19Z") :: DateTime.DateTime):toLocalTime()
local dateTime = DateTime.fromUnixTimestamp(1693115659):toLocalTime()
local expectedDateTimeValues = table.pack(
string.match(
"2023-08-27T11:24:19Z",
"(%d%d%d%d)-?(%d?%d?)-?(%d?%d?)T(%d?%d?):(%d?%d?):(%d?%d?)Z$"
)
local expectedDateTimeValues = os.date("*t", 1693115659)
assert(
dateTime.year == expectedDateTimeValues.year,
`expected {dateTime.year} == {expectedDateTimeValues.year}`
)
assert(
dateTime.month == expectedDateTimeValues.month,
`expected {dateTime.month} == {expectedDateTimeValues.month}`
)
assert(
dateTime.day == expectedDateTimeValues.day,
`expected {dateTime.day} == {expectedDateTimeValues.day}`
)
assert(
dateTime.hour == expectedDateTimeValues.hour,
`expected {dateTime.hour} == {expectedDateTimeValues.hour}`
)
assert(
dateTime.minute == expectedDateTimeValues.min,
`expected {dateTime.minute} == {expectedDateTimeValues.min}`
)
assert(
dateTime.second == expectedDateTimeValues.sec,
`expected {dateTime.second} == {expectedDateTimeValues.sec}`
)
local expectedYear = tonumber(expectedDateTimeValues[1])
local expectedMonth = tonumber(expectedDateTimeValues[2])
local expectedDay = tonumber(expectedDateTimeValues[3])
local expectedHour = tonumber(expectedDateTimeValues[4])
local expectedMinute = tonumber(expectedDateTimeValues[5])
local expectedSecond = tonumber(expectedDateTimeValues[6])
assert(dateTime.year == expectedYear, `expected {dateTime.year} == {expectedYear}`)
assert(dateTime.month == expectedMonth, `expected {dateTime.month} == {expectedMonth}`)
assert(dateTime.day == expectedDay, `expected {dateTime.day} == {expectedDay}`)
assert(dateTime.hour == expectedHour, `expected {dateTime.hour} == {expectedHour}`)
assert(dateTime.minute == expectedMinute, `expected {dateTime.minute} == {expectedMinute}`)
assert(dateTime.second == expectedSecond, `expected {dateTime.second} == {expectedSecond}`)