Skip to content

Commit 62a4106

Browse files
refactor(date): Refactor date object (#869)
1 parent e385fcf commit 62a4106

File tree

11 files changed

+474
-466
lines changed

11 files changed

+474
-466
lines changed

lua/orgmode/agenda/types/agenda.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function OrgAgendaType:new(opts)
7171
category_filter = opts.category_filter and AgendaFilter:new({ types = { 'categories' } })
7272
:parse(opts.category_filter, true) or nil,
7373
span = opts.span or config:get_agenda_span(),
74-
from = opts.from or Date.now():start_of('day'),
74+
from = opts.from or Date.today(),
7575
to = nil,
7676
clock_report = nil,
7777
show_clock_report = opts.show_clock_report or false,
@@ -160,7 +160,7 @@ function OrgAgendaType:goto_date(date)
160160
end
161161

162162
function OrgAgendaType:reset()
163-
return self:goto_date(Date.now():start_of('day'))
163+
return self:goto_date(Date.today())
164164
end
165165

166166
---@return OrgAgendaLine[]

lua/orgmode/agenda/types/tags.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
local Date = require('orgmode.objects.date')
33
local config = require('orgmode.config')
44
local utils = require('orgmode.utils')
5-
local validator = require('orgmode.utils.validator')
65
local Search = require('orgmode.files.elements.search')
76
local OrgAgendaTodosType = require('orgmode.agenda.types.todo')
87

@@ -58,11 +57,11 @@ function OrgAgendaTagsType:get_file_headlines(file)
5857
return false
5958
end
6059
if self.todo_ignore_deadlines == 'near' then
61-
local diff = deadline_date:diff(Date.now())
60+
local diff = deadline_date:diff(Date.now(), 'day')
6261
return diff > config.org_deadline_warning_days
6362
end
6463
if self.todo_ignore_deadlines == 'far' then
65-
local diff = deadline_date:diff(Date.now())
64+
local diff = deadline_date:diff(Date.now(), 'day')
6665
return diff <= config.org_deadline_warning_days
6766
end
6867
if self.todo_ignore_deadlines == 'past' then

lua/orgmode/capture/template/datetree.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
local utils = require('orgmode.utils')
2-
local Date = require('orgmode.objects.date')
32

43
---@class OrgDatetree
54
---@field files OrgFiles

lua/orgmode/capture/template/init.lua

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,51 +23,51 @@ local expansions = {
2323
end,
2424
['%%%^t'] = function()
2525
return Calendar.new({ date = Date.today() }):open():next(function(date)
26-
return date and string.format('<%s>', date:to_string()) or nil
26+
return date and date:to_wrapped_string(true) or nil
2727
end)
2828
end,
2929
['%%%^%{([^%}]*)%}t'] = function(title)
3030
return Calendar.new({ date = Date.today(), title = title }):open():next(function(date)
31-
return date and string.format('<%s>', date:to_string()) or nil
31+
return date and date:to_wrapped_string(true) or nil
3232
end)
3333
end,
3434
['%%T'] = function()
35-
return string.format('<%s>', Date.now():to_string())
35+
return Date.now():to_wrapped_string(true)
3636
end,
3737
['%%%^T'] = function()
3838
return Calendar.new({ date = Date.now() }):open():next(function(date)
39-
return date and string.format('<%s>', date:to_string()) or nil
39+
return date and date:to_wrapped_string(true) or nil
4040
end)
4141
end,
4242
['%%%^%{([^%}]*)%}T'] = function(title)
4343
return Calendar.new({ date = Date.now(), title = title }):open():next(function(date)
44-
return date and string.format('<%s>', date:to_string()) or nil
44+
return date and date:to_wrapped_string(true) or nil
4545
end)
4646
end,
4747
['%%u'] = function()
48-
return string.format('[%s]', Date.today():to_string())
48+
return Date.today():to_wrapped_string(false)
4949
end,
5050
['%%%^u'] = function()
5151
return Calendar.new({ date = Date.today() }):open():next(function(date)
52-
return date and string.format('[%s]', date:to_string()) or nil
52+
return date and date:to_wrapped_string(false) or nil
5353
end)
5454
end,
5555
['%%%^%{([^%}]*)%}u'] = function(title)
5656
return Calendar.new({ date = Date.today(), title = title }):open():next(function(date)
57-
return date and string.format('[%s]', date:to_string()) or nil
57+
return date and date:to_wrapped_string(false) or nil
5858
end)
5959
end,
6060
['%%U'] = function()
61-
return string.format('[%s]', Date.now():to_string())
61+
return Date.now():to_wrapped_string(false)
6262
end,
6363
['%%%^U'] = function()
6464
return Calendar.new({ date = Date.now() }):open():next(function(date)
65-
return date and string.format('[%s]', date:to_string()) or nil
65+
return date and date:to_wrapped_string(false) or nil
6666
end)
6767
end,
6868
['%%%^%{([^%}]*)%}U'] = function(title)
6969
return Calendar.new({ date = Date.now(), title = title }):open():next(function(date)
70-
return date and string.format('[%s]', date:to_string()) or nil
70+
return date and date:to_wrapped_string(false) or nil
7171
end)
7272
end,
7373
['%%a'] = function()

lua/orgmode/files/elements/search.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,14 +396,14 @@ function PropertyMatch:parse(input)
396396
---@type string?, OrgDate?
397397
local date_content, date_value
398398
if date_str == '<today>' then
399-
date_value = Date.today():start_of('day')
399+
date_value = Date.today()
400400
elseif date_str == '<tomorrow>' then
401-
date_value = Date.tomorrow():start_of('day')
401+
date_value = Date.tomorrow()
402402
else
403403
-- Parse relative formats (e.g. <+1d>) as well as absolute
404404
date_content = date_str:match('^<([%+%-]%d+[dmyhwM])>$')
405405
if date_content then
406-
date_value = Date.today():start_of('day')
406+
date_value = Date.today()
407407
date_value = date_value:adjust(date_content)
408408
else
409409
date_content = date_str:match('^<([^>]+)>$')

lua/orgmode/files/headline.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ function Headline:get_valid_dates_for_agenda()
775775
for _, date in ipairs(self:get_all_dates()) do
776776
if date.active and not date:is_closed() and not date:is_obsolete_range_end() then
777777
table.insert(dates, date)
778-
if not date:is_none() and date.related_date_range then
778+
if not date:is_none() and date.related_date then
779779
local new_date = date:clone({ type = 'NONE' })
780780
table.insert(dates, new_date)
781781
end

lua/orgmode/notifications/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ end
2222
function Notifications:start_timer()
2323
self:stop_timer()
2424
self.timer = vim.loop.new_timer()
25-
self:notify(Date.now():start_of('minute'))
25+
self:notify(Date.now())
2626
self.timer:start(
2727
(60 - os.date('%S')) * 1000,
2828
60000,
@@ -62,7 +62,7 @@ function Notifications:notify(time)
6262
end
6363

6464
function Notifications:cron()
65-
local tasks = self:get_tasks(Date.now():start_of('minute'))
65+
local tasks = self:get_tasks(Date.now())
6666
if type(config.notifications.cron_notifier) == 'function' then
6767
config.notifications.cron_notifier(tasks)
6868
else

0 commit comments

Comments
 (0)