Compare commits
2 Commits
63bb1e67e0
...
6b8b4de21e
Author | SHA1 | Date | |
---|---|---|---|
|
6b8b4de21e | ||
|
a67bde58d0 |
@ -8,7 +8,7 @@ import re
|
||||
import sys
|
||||
from datetime import date, datetime, timedelta
|
||||
from enum import Enum
|
||||
from typing import Generator, List, Tuple, Union
|
||||
from typing import Generator, List, Optional, Tuple, Union
|
||||
|
||||
from . import dom
|
||||
|
||||
@ -779,7 +779,7 @@ class Timestamp:
|
||||
self.minute = minute
|
||||
self.repetition = repetition
|
||||
|
||||
def to_datetime(self) -> Union[datetime, date]:
|
||||
def to_datetime(self) -> datetime:
|
||||
if self.hour is not None:
|
||||
return datetime(self.year, self.month, self.day, self.hour, self.minute)
|
||||
else:
|
||||
@ -955,11 +955,15 @@ def parse_org_time_range(start, end) -> TimeRange:
|
||||
|
||||
|
||||
class OrgTime:
|
||||
def __init__(self, ts: Timestamp, end_time: Union[Timestamp, None] = None):
|
||||
def __init__(self, ts: Timestamp, end_time: Optional[Timestamp] = None):
|
||||
assert ts is not None
|
||||
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,
|
||||
)
|
||||
)
|
||||
|
||||
@ -1026,7 +1035,7 @@ def timerange_to_string(tr: TimeRange):
|
||||
return tr.start_time.to_raw() + "--" + tr.end_time.to_raw()
|
||||
|
||||
|
||||
def timestamp_to_string(ts: Timestamp, end_time: Union[Timestamp, None] = None) -> str:
|
||||
def timestamp_to_string(ts: Timestamp, end_time: Optional[Timestamp] = None) -> str:
|
||||
date = "{year}-{month:02d}-{day:02d}".format(
|
||||
year=ts.year, month=ts.month, day=ts.day
|
||||
)
|
||||
@ -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:
|
||||
|
@ -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>
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user