Skip to content

Commit 4ca905a

Browse files
committed
fix(date): persist all attributes passed by options
Store all attributes passed as option via Date:set, especially date_only.
1 parent cb3c9bf commit 4ca905a

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

lua/orgmode/objects/date.lua

+18-12
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,27 @@ end
9595
---@param time table
9696
---@return OrgDate
9797
function Date:from_time_table(time)
98-
local range_diff = self.timestamp_end and self.timestamp_end - self.timestamp or 0
99-
local timestamp = os.time(set_date_opts(time, {}, true))
98+
local timestamp_end = time.timestamp_end or self.timestamp_end
99+
local timestamp = time.timestamp or self.timestamp
100+
local range_diff = timestamp_end and timestamp_end - timestamp or 0
101+
timestamp = os.time(set_date_opts(time, {}, true))
100102
local opts = set_date_opts(os.date('*t', timestamp))
101-
opts.date_only = self.date_only
102-
opts.dayname = self.dayname
103-
opts.adjustments = self.adjustments
104-
opts.type = self.type
105-
opts.active = self.active
106-
opts.range = self.range
107-
if self.timestamp_end then
103+
if time.date_only ~= nil then
104+
opts.date_only = time.date_only
105+
else
106+
opts.date_only = self.date_only
107+
end
108+
opts.dayname = time.dayname or self.dayname
109+
opts.adjustments = time.adjustments or self.adjustments
110+
opts.type = time.type or self.type
111+
opts.active = time.active or self.active
112+
opts.range = time.range or self.range
113+
if time.timestamp_end or self.timestamp_end then
108114
opts.timestamp_end = timestamp + range_diff
109115
end
110-
opts.is_date_range_start = self.is_date_range_start
111-
opts.is_date_range_end = self.is_date_range_end
112-
opts.related_date_range = self.related_date_range
116+
opts.is_date_range_start = time.is_date_range_start or self.is_date_range_start
117+
opts.is_date_range_end = time.is_date_range_end or self.is_date_range_end
118+
opts.related_date_range = time.related_date_range or self.related_date_range
113119
return Date:new(opts)
114120
end
115121

0 commit comments

Comments
 (0)