Skip to content

Commit fa5a0c4

Browse files
committed
fix: datetime sorting and other minor fixes
1 parent e4ef748 commit fa5a0c4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Diff for: lua/neowarrior/DateTime.lua

+7-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function DateTime:new(input)
2828
self.__index = self
2929

3030
datetime.date = date(input)
31+
datetime.timestamp = datetime.date:spanseconds()
3132

3233
return datetime
3334
end
@@ -38,7 +39,7 @@ end
3839

3940
--- Add time to date
4041
---@param unit "years"|"months"|"days"|"hours"|"minutes"|"seconds"
41-
---@param value
42+
---@param value number
4243
function DateTime:add(unit, value)
4344

4445
if unit == "years" then
@@ -82,7 +83,7 @@ function DateTime:nice(opts)
8283
local default_format = opts and opts.format or "%A, %B %d"
8384
local show_close_dates = opts and opts.show_close_dates or false
8485
local now = DateTime:new(nil)
85-
local days = math.ceil(date.diff(self.date, now.date):spandays())
86+
local days = math.floor(date.diff(self.date, now.date):spandays())
8687

8788
local str = "In " .. days .. " days"
8889

@@ -186,6 +187,10 @@ end
186187
--- Get relative hours
187188
--- @return number
188189
function DateTime:relative_hours()
190+
return self:diff_hours()
191+
end
192+
193+
function DateTime:diff_hours()
189194
local diff = self:diff_object()
190195
return diff:spanhours()
191196
end

0 commit comments

Comments
 (0)