From a67bde58d07b11b2f96994c1e6919dd075aa0fdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Sun, 5 Jun 2022 23:31:48 +0200 Subject: [PATCH] Fix repetition on dates with start+end times. --- org_rw/org_rw.py | 13 +++++++++++-- tests/05-dates.org | 3 +++ tests/test_org.py | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/org_rw/org_rw.py b/org_rw/org_rw.py index b4526be..e3dca6d 100644 --- a/org_rw/org_rw.py +++ b/org_rw/org_rw.py @@ -960,6 +960,10 @@ class OrgTime: self.time = ts self.end_time = end_time + @property + def repetition(self): + return self.time.repetition + @property def duration(self): if self.end_time is None: @@ -982,6 +986,10 @@ class OrgTime: else: return None + repetition = None + if m.group("repetition"): + repetition = m.group("repetition").strip() + if m.group("end_hour"): return OrgTime( Timestamp( @@ -992,6 +1000,7 @@ class OrgTime: m.group("dow"), int(m.group("start_hour")), int(m.group("start_minute")), + repetition=repetition, ), Timestamp( active, @@ -1013,7 +1022,7 @@ class OrgTime: m.group("dow"), int(m.group("start_hour")) if m.group("start_hour") else None, int(m.group("start_minute")) if m.group("start_minute") else None, - m.group("repetition").strip() if m.group("repetition") else None, + repetition=repetition, ) ) @@ -1047,7 +1056,7 @@ def timestamp_to_string(ts: Timestamp, end_time: Union[Timestamp, None] = None) base=base, hour=end_time.hour, minute=end_time.minute ) - if ts.repetition: + if ts.repetition is not None: base = base + " " + ts.repetition if ts.active: diff --git a/tests/05-dates.org b/tests/05-dates.org index 8b1de23..96e08f8 100644 --- a/tests/05-dates.org +++ b/tests/05-dates.org @@ -19,3 +19,6 @@ SCHEDULED: <2020-12-12 Sáb> CLOSED: <2020-12-13 Dom> DEADLINE: <2020-12-14 Lun> ** Scheduled for time range SCHEDULED: <2020-12-15 Mar 00:05-00:10> + +** Scheduled periodic +SCHEDULED: <2020-12-15 Mar 00:05-00:10 ++1w> diff --git a/tests/test_org.py b/tests/test_org.py index fc27430..d7c9234 100644 --- a/tests/test_org.py +++ b/tests/test_org.py @@ -418,6 +418,20 @@ class TestSerde(unittest.TestCase): Timestamp(True, 2020, 12, 15, "Mar", 0, 10), ) + hl_schedule_range = hl.children[1] + self.assertEqual( + hl_schedule_range.scheduled.time, + Timestamp(True, 2020, 12, 15, "Mar", 0, 5, '++1w') + ) + self.assertEqual( + hl_schedule_range.scheduled.end_time, + Timestamp(True, 2020, 12, 15, "Mar", 0, 10), + ) + self.assertEqual( + hl_schedule_range.scheduled.repetition, + '++1w', + ) + def test_update_info_file_05(self): with open(os.path.join(DIR, "05-dates.org")) as f: orig = f.read()