Skip to content

refactor(date): Refactor date object #869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lua/orgmode/agenda/types/agenda.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function OrgAgendaType:new(opts)
category_filter = opts.category_filter and AgendaFilter:new({ types = { 'categories' } })
:parse(opts.category_filter, true) or nil,
span = opts.span or config:get_agenda_span(),
from = opts.from or Date.now():start_of('day'),
from = opts.from or Date.today(),
to = nil,
clock_report = nil,
show_clock_report = opts.show_clock_report or false,
Expand Down Expand Up @@ -160,7 +160,7 @@ function OrgAgendaType:goto_date(date)
end

function OrgAgendaType:reset()
return self:goto_date(Date.now():start_of('day'))
return self:goto_date(Date.today())
end

---@return OrgAgendaLine[]
Expand Down
5 changes: 2 additions & 3 deletions lua/orgmode/agenda/types/tags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
local Date = require('orgmode.objects.date')
local config = require('orgmode.config')
local utils = require('orgmode.utils')
local validator = require('orgmode.utils.validator')
local Search = require('orgmode.files.elements.search')
local OrgAgendaTodosType = require('orgmode.agenda.types.todo')

Expand Down Expand Up @@ -58,11 +57,11 @@ function OrgAgendaTagsType:get_file_headlines(file)
return false
end
if self.todo_ignore_deadlines == 'near' then
local diff = deadline_date:diff(Date.now())
local diff = deadline_date:diff(Date.now(), 'day')
return diff > config.org_deadline_warning_days
end
if self.todo_ignore_deadlines == 'far' then
local diff = deadline_date:diff(Date.now())
local diff = deadline_date:diff(Date.now(), 'day')
return diff <= config.org_deadline_warning_days
end
if self.todo_ignore_deadlines == 'past' then
Expand Down
1 change: 0 additions & 1 deletion lua/orgmode/capture/template/datetree.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local utils = require('orgmode.utils')
local Date = require('orgmode.objects.date')

---@class OrgDatetree
---@field files OrgFiles
Expand Down
22 changes: 11 additions & 11 deletions lua/orgmode/capture/template/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,51 @@ local expansions = {
end,
['%%%^t'] = function()
return Calendar.new({ date = Date.today() }):open():next(function(date)
return date and string.format('<%s>', date:to_string()) or nil
return date and date:to_wrapped_string(true) or nil
end)
end,
['%%%^%{([^%}]*)%}t'] = function(title)
return Calendar.new({ date = Date.today(), title = title }):open():next(function(date)
return date and string.format('<%s>', date:to_string()) or nil
return date and date:to_wrapped_string(true) or nil
end)
end,
['%%T'] = function()
return string.format('<%s>', Date.now():to_string())
return Date.now():to_wrapped_string(true)
end,
['%%%^T'] = function()
return Calendar.new({ date = Date.now() }):open():next(function(date)
return date and string.format('<%s>', date:to_string()) or nil
return date and date:to_wrapped_string(true) or nil
end)
end,
['%%%^%{([^%}]*)%}T'] = function(title)
return Calendar.new({ date = Date.now(), title = title }):open():next(function(date)
return date and string.format('<%s>', date:to_string()) or nil
return date and date:to_wrapped_string(true) or nil
end)
end,
['%%u'] = function()
return string.format('[%s]', Date.today():to_string())
return Date.today():to_wrapped_string(false)
end,
['%%%^u'] = function()
return Calendar.new({ date = Date.today() }):open():next(function(date)
return date and string.format('[%s]', date:to_string()) or nil
return date and date:to_wrapped_string(false) or nil
end)
end,
['%%%^%{([^%}]*)%}u'] = function(title)
return Calendar.new({ date = Date.today(), title = title }):open():next(function(date)
return date and string.format('[%s]', date:to_string()) or nil
return date and date:to_wrapped_string(false) or nil
end)
end,
['%%U'] = function()
return string.format('[%s]', Date.now():to_string())
return Date.now():to_wrapped_string(false)
end,
['%%%^U'] = function()
return Calendar.new({ date = Date.now() }):open():next(function(date)
return date and string.format('[%s]', date:to_string()) or nil
return date and date:to_wrapped_string(false) or nil
end)
end,
['%%%^%{([^%}]*)%}U'] = function(title)
return Calendar.new({ date = Date.now(), title = title }):open():next(function(date)
return date and string.format('[%s]', date:to_string()) or nil
return date and date:to_wrapped_string(false) or nil
end)
end,
['%%a'] = function()
Expand Down
6 changes: 3 additions & 3 deletions lua/orgmode/files/elements/search.lua
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,14 @@ function PropertyMatch:parse(input)
---@type string?, OrgDate?
local date_content, date_value
if date_str == '<today>' then
date_value = Date.today():start_of('day')
date_value = Date.today()
elseif date_str == '<tomorrow>' then
date_value = Date.tomorrow():start_of('day')
date_value = Date.tomorrow()
else
-- Parse relative formats (e.g. <+1d>) as well as absolute
date_content = date_str:match('^<([%+%-]%d+[dmyhwM])>$')
if date_content then
date_value = Date.today():start_of('day')
date_value = Date.today()
date_value = date_value:adjust(date_content)
else
date_content = date_str:match('^<([^>]+)>$')
Expand Down
2 changes: 1 addition & 1 deletion lua/orgmode/files/headline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ function Headline:get_valid_dates_for_agenda()
for _, date in ipairs(self:get_all_dates()) do
if date.active and not date:is_closed() and not date:is_obsolete_range_end() then
table.insert(dates, date)
if not date:is_none() and date.related_date_range then
if not date:is_none() and date.related_date then
local new_date = date:clone({ type = 'NONE' })
table.insert(dates, new_date)
end
Expand Down
4 changes: 2 additions & 2 deletions lua/orgmode/notifications/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end
function Notifications:start_timer()
self:stop_timer()
self.timer = vim.loop.new_timer()
self:notify(Date.now():start_of('minute'))
self:notify(Date.now())
self.timer:start(
(60 - os.date('%S')) * 1000,
60000,
Expand Down Expand Up @@ -62,7 +62,7 @@ function Notifications:notify(time)
end

function Notifications:cron()
local tasks = self:get_tasks(Date.now():start_of('minute'))
local tasks = self:get_tasks(Date.now())
if type(config.notifications.cron_notifier) == 'function' then
config.notifications.cron_notifier(tasks)
else
Expand Down
Loading
Loading