Created
January 16, 2025 22:25
-
-
Save Dekkonot/93b530a2f0c89e3bc0b707b747e6c916 to your computer and use it in GitHub Desktop.
Implementation of today and tomorrow for Lune's datetime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local datetime = require("@lune/datetime") | |
local function tomorrow(date: datetime.DateTime): datetime.DateTime | |
local time: any = table.clone(date:toUniversalTime()) | |
time.day += 1 | |
local success, future = pcall(datetime.fromUniversalTime, time) | |
if success then | |
return future | |
else | |
time.day = 1 | |
time.month += 1 | |
if time.month == 13 then | |
time.month = 1 | |
time.year += 1 | |
end | |
future = datetime.fromUniversalTime(time) | |
return future | |
end | |
end | |
local function yesterday(date: datetime.DateTime): datetime.DateTime | |
local time: any = table.clone(date:toUniversalTime()) | |
time.day -= 1 | |
local success, future = pcall(datetime.fromUniversalTime, time) | |
if success then | |
return future | |
else | |
time.month -= 1 | |
if time.month == 0 then | |
time.day = 31 | |
time.month = 12 | |
time.year -= 1 | |
return datetime.fromUniversalTime(time) | |
else | |
time.day = 31 | |
repeat | |
success, future = pcall(datetime.fromUniversalTime, time) | |
time.day -= 1 | |
until success | |
return future | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment