diff --git a/tests/datetime/toUniversalTime.luau b/tests/datetime/toUniversalTime.luau index 47e1ebe..1fe47a7 100644 --- a/tests/datetime/toUniversalTime.luau +++ b/tests/datetime/toUniversalTime.luau @@ -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}`)