Skip to content

Date Searching #487

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 26 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
717223e
Improves type annotation of `Section.properties`
chuck-flowers Jan 6, 2023
4bd06b3
Improves Search annotations
chuck-flowers Jan 6, 2023
70230cf
Comments the existing Search:_matches behavior
chuck-flowers Jan 11, 2023
e1fd214
Implements operators for dates
chuck-flowers Jan 12, 2023
aa0fb25
Totally reworks the Search query parsing logic
chuck-flowers Jan 12, 2023
c26f861
Fixes an error in the parse_delimited_sequence function
chuck-flowers Jan 15, 2023
9c4ba33
Fixes error in parsing a sequence of `AndItem`s
chuck-flowers Jan 15, 2023
105d9c4
Supports defines tags as a single string or array of strings
chuck-flowers Jan 15, 2023
a71ea1c
Corrected a failing test to reflect the internal object changes
chuck-flowers Jan 16, 2023
e2a2616
Adds quoting to string query properties in testing as is required by …
chuck-flowers Jan 16, 2023
9515f10
Fixes a bug in the todo matching logic
chuck-flowers Jan 16, 2023
96c4320
Fixes type issues in the `search_spec` test
chuck-flowers Jan 16, 2023
4b12d20
Removes print statements
chuck-flowers Jan 18, 2023
58dc769
Adds a `tomorrow` function
chuck-flowers Jan 18, 2023
c37212f
Supports relative dates (e.g. <+1d> or <tomorrow>)
chuck-flowers Jan 18, 2023
1530e43
Includes SCHEDULED, CLOSED, and DEADLINE in props
chuck-flowers Jan 24, 2023
b775ad4
Fixes a bug in the relative date search
chuck-flowers Jan 24, 2023
94da6be
Removes debug print
chuck-flowers Jan 24, 2023
9e12ee9
Fixes unit tests
chuck-flowers Jan 24, 2023
96c8515
Injects DEADLINE, SCHEDULED, and CLOSED as Searchable props
chuck-flowers Jan 25, 2023
c6c0e21
Revert "Fixes unit tests"
chuck-flowers Jan 25, 2023
72ada79
No longer includes scheduling dates as props
chuck-flowers Jan 25, 2023
afb5e36
Reverts changes to tests
chuck-flowers Mar 15, 2023
3b24bd0
Fixes a test that broke do to changing the "AST" of Search
chuck-flowers Mar 15, 2023
96c35e7
Updates a test to quote string props as is required by Emacs
chuck-flowers Mar 15, 2023
335fdde
Corrects a type issue of the todo keyword prop
chuck-flowers Mar 15, 2023
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
30 changes: 29 additions & 1 deletion lua/orgmode/objects/date.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,28 @@ local time_format = '%H:%M'
---@field related_date_range Date
---@field dayname string
---@field adjustments string[]
local Date = {}
local Date = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very good change, I completely forgot about metamethods.

---@type fun(this: Date, other: Date): boolean
__eq = function(this, other)
return this.timestamp == other.timestamp
end,
---@type fun(this: Date, other: Date): boolean
__lt = function(this, other)
return this.timestamp < other.timestamp
end,
---@type fun(this: Date, other: Date): boolean
__le = function(this, other)
return this.timestamp <= other.timestamp
end,
---@type fun(this: Date, other: Date): boolean
__gt = function(this, other)
return this.timestamp > other.timestamp
end,
---@type fun(this: Date, other: Date): boolean
__ge = function(this, other)
return this.timestamp >= other.timestamp
end,
}

---@param source table
---@param target? table
Expand Down Expand Up @@ -166,6 +187,12 @@ local function today(data)
return Date:new(opts)
end

---@return Date
local function tomorrow()
local today_date = today()
return today_date:adjust('+1d')
end

---@param data? table
---@return Date
local function now(data)
Expand Down Expand Up @@ -909,6 +936,7 @@ return {
from_string = from_string,
now = now,
today = today,
tomorrow = tomorrow,
parse_all_from_line = parse_all_from_line,
is_valid_date = is_valid_date,
is_date_instance = is_date_instance,
Expand Down
8 changes: 8 additions & 0 deletions lua/orgmode/parser/file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,17 @@ function File:apply_search(search, todo_only)
if item:is_archived() or (todo_only and not item:is_todo()) then
return false
end

local deadline = item:get_deadline_date()
local scheduled = item:get_scheduled_date()
local closed = item:get_closed_date()

return search:check({
props = vim.tbl_extend('keep', {}, item.properties.items, {
category = item.category,
deadline = deadline and deadline:to_wrapped_string(true),
scheduled = scheduled and scheduled:to_wrapped_string(true),
closed = closed and closed:to_wrapped_string(false),
}),
tags = item.tags,
todo = item.todo_keyword.value,
Expand Down
Loading