Skip to content

Commit b321cc9

Browse files
Parse timestamps from headline. Closes #177
1 parent f04576a commit b321cc9

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

lua/orgmode/parser/section.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ function Section.from_node(section_node, file, parent)
152152

153153
if child:type() == 'headline' then
154154
data.line = file:get_node_text(child)
155+
utils.concat(data.dates, Date.parse_all_from_line(data.line, data.range.start_line))
155156
data.level = file:get_node_text(child:child(0)):len()
156157
for headline_node in child:iter_children() do
157158
if headline_node:type() == 'item' then

tests/plenary/parser/parser_spec.lua

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,15 @@ describe('Parser', function()
249249
own_tags = { 'WORK' },
250250
category = 'work',
251251
dates = {
252-
-- TODO: Uncomment this when support for headline dates is added
253-
-- Date.from_string('2021-05-15 Sat', {
254-
-- active = true,
255-
-- range = Range:new({
256-
-- start_line = 1,
257-
-- end_line = 1,
258-
-- start_col = 21,
259-
-- end_col = 36,
260-
-- }),
261-
-- }),
252+
Date.from_string('2021-05-15 Sat', {
253+
active = true,
254+
range = Range:new({
255+
start_line = 1,
256+
end_line = 1,
257+
start_col = 21,
258+
end_col = 36,
259+
}),
260+
}),
262261
Date.from_string('2021-05-20 Thu', {
263262
type = 'DEADLINE',
264263
active = true,
@@ -691,4 +690,44 @@ describe('Parser', function()
691690
category = 'work',
692691
})
693692
end)
693+
694+
it('should parse dates from headline', function()
695+
local lines = {
696+
'* TODO Test with date <2022-05-02 Mon 12:00>',
697+
}
698+
699+
local parsed = File.from_content(lines, 'work', '')
700+
701+
assert_section(parsed, parsed:get_section(1), {
702+
line = '* TODO Test with date <2022-05-02 Mon 12:00>',
703+
line_number = 1,
704+
level = 1,
705+
title = 'Test with date <2022-05-02 Mon 12:00>',
706+
todo_keyword = {
707+
type = 'TODO',
708+
value = 'TODO',
709+
range = Range:new({
710+
start_line = 1,
711+
end_line = 1,
712+
start_col = 3,
713+
end_col = 6,
714+
}),
715+
},
716+
tags = {},
717+
own_tags = {},
718+
category = 'work',
719+
dates = {
720+
Date.from_string('2022-05-02 Mon 12:00', {
721+
type = 'NONE',
722+
active = true,
723+
range = Range:new({
724+
start_line = 1,
725+
end_line = 1,
726+
start_col = 23,
727+
end_col = 44,
728+
}),
729+
}),
730+
},
731+
})
732+
end)
694733
end)

0 commit comments

Comments
 (0)