@@ -30,23 +30,38 @@ local time_format = '%H:%M'
30
30
local Date = {
31
31
--- @type fun ( this : OrgDate , other : OrgDate ): boolean
32
32
__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 )
34
37
end ,
35
38
--- @type fun ( this : OrgDate , other : OrgDate ): boolean
36
39
__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 )
38
44
end ,
39
45
--- @type fun ( this : OrgDate , other : OrgDate ): boolean
40
46
__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 )
42
51
end ,
43
52
--- @type fun ( this : OrgDate , other : OrgDate ): boolean
44
53
__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 )
46
58
end ,
47
59
--- @type fun ( this : OrgDate , other : OrgDate ): boolean
48
60
__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 )
50
65
end ,
51
66
}
52
67
@@ -85,7 +100,7 @@ function Date:new(data)
85
100
opts .active = data .active or false
86
101
opts .range = data .range
87
102
opts .timestamp = os.time (opts )
88
- opts .date_only = date_only
103
+ opts .date_only = date_only or false
89
104
opts .dayname = os.date (' %a' , opts .timestamp ) --[[ @as string]]
90
105
opts .is_dst = os_date (opts .timestamp ).isdst
91
106
opts .adjustments = data .adjustments or {}
@@ -628,7 +643,7 @@ function Date:is_before(date, span)
628
643
end
629
644
630
645
--- @param date OrgDate
631
- --- @param span string
646
+ --- @param span ? string
632
647
--- @return boolean
633
648
function Date :is_same_or_before (date , span )
634
649
local d = date
@@ -641,7 +656,7 @@ function Date:is_same_or_before(date, span)
641
656
end
642
657
643
658
--- @param date OrgDate
644
- --- @param span string
659
+ --- @param span ? string
645
660
--- @return boolean
646
661
function Date :is_after (date , span )
647
662
return not self :is_same_or_before (date , span )
0 commit comments