feat: add day menu
This commit is contained in:
46
src/lib/dates.lua
Normal file
46
src/lib/dates.lua
Normal file
@@ -0,0 +1,46 @@
|
||||
local dates = {}
|
||||
|
||||
---Checks whether date2 is after date1
|
||||
---@param date1 any
|
||||
---@param date2 any
|
||||
---@return boolean
|
||||
function dates.isAfter(date1, date2)
|
||||
if date2.year < date1.year then
|
||||
return false
|
||||
elseif date2.year > date1.year then
|
||||
return true
|
||||
end
|
||||
if date2.month < date1.month then
|
||||
return false
|
||||
elseif date2.month > date1.month then
|
||||
return true
|
||||
end
|
||||
return date2.day > date1.day
|
||||
end
|
||||
|
||||
---Checks whether date2 is before date1
|
||||
---@param date1 any
|
||||
---@param date2 any
|
||||
---@return boolean
|
||||
function dates.isBefore(date1, date2)
|
||||
if date2.year > date1.year then
|
||||
return false
|
||||
elseif date2.year < date1.year then
|
||||
return true
|
||||
end
|
||||
if date2.month > date1.month then
|
||||
return false
|
||||
elseif date2.month < date1.month then
|
||||
return true
|
||||
end
|
||||
return date2.day < date1.day
|
||||
end
|
||||
|
||||
function dates.isInDateRange(startDate, targetDate, endDate)
|
||||
return not (
|
||||
dates.isBefore(startDate, targetDate) or
|
||||
dates.isAfter(endDate, targetDate)
|
||||
)
|
||||
end
|
||||
|
||||
return dates
|
||||
Reference in New Issue
Block a user