Skip to content

Commit fccccd4

Browse files
fix(dates): Check if date is without a time when doing comparison
When comparing two dates, and one does not have a specified time, comparison should check only dates.
1 parent 43361ba commit fccccd4

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

lua/orgmode/objects/date.lua

+23-8
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,38 @@ local time_format = '%H:%M'
3030
local Date = {
3131
---@type fun(this: OrgDate, other: OrgDate): boolean
3232
__eq = function(this, other)
33-
return this.timestamp == other.timestamp
33+
if this.date_only ~= other.date_only then
34+
return this:is_same(other, 'day')
35+
end
36+
return this:is_same(other)
3437
end,
3538
---@type fun(this: OrgDate, other: OrgDate): boolean
3639
__lt = function(this, other)
37-
return this.timestamp < other.timestamp
40+
if this.date_only ~= other.date_only then
41+
return this:is_before(other, 'day')
42+
end
43+
return this:is_before(other)
3844
end,
3945
---@type fun(this: OrgDate, other: OrgDate): boolean
4046
__le = function(this, other)
41-
return this.timestamp <= other.timestamp
47+
if this.date_only ~= other.date_only then
48+
return this:is_same_or_before(other, 'day')
49+
end
50+
return this:is_same_or_before(other)
4251
end,
4352
---@type fun(this: OrgDate, other: OrgDate): boolean
4453
__gt = function(this, other)
45-
return this.timestamp > other.timestamp
54+
if this.date_only ~= other.date_only then
55+
return this:is_after(other, 'day')
56+
end
57+
return this:is_after(other)
4658
end,
4759
---@type fun(this: OrgDate, other: OrgDate): boolean
4860
__ge = function(this, other)
49-
return this.timestamp >= other.timestamp
61+
if this.date_only ~= other.date_only then
62+
return this:is_same_or_after(other, 'day')
63+
end
64+
return this:is_same_or_after(other)
5065
end,
5166
}
5267

@@ -85,7 +100,7 @@ function Date:new(data)
85100
opts.active = data.active or false
86101
opts.range = data.range
87102
opts.timestamp = os.time(opts)
88-
opts.date_only = date_only
103+
opts.date_only = date_only or false
89104
opts.dayname = os.date('%a', opts.timestamp) --[[@as string]]
90105
opts.is_dst = os_date(opts.timestamp).isdst
91106
opts.adjustments = data.adjustments or {}
@@ -628,7 +643,7 @@ function Date:is_before(date, span)
628643
end
629644

630645
---@param date OrgDate
631-
---@param span string
646+
---@param span? string
632647
---@return boolean
633648
function Date:is_same_or_before(date, span)
634649
local d = date
@@ -641,7 +656,7 @@ function Date:is_same_or_before(date, span)
641656
end
642657

643658
---@param date OrgDate
644-
---@param span string
659+
---@param span? string
645660
---@return boolean
646661
function Date:is_after(date, span)
647662
return not self:is_same_or_before(date, span)

0 commit comments

Comments
 (0)