Compare commits
No commits in common. "6b8b4de21e8327fbbfb0b986d3f6e2aa913e44af" and "63bb1e67e0e312c35f0d0c85269330da9f3e8d28" have entirely different histories.
6b8b4de21e
...
63bb1e67e0
@ -8,7 +8,7 @@ import re
|
||||
import sys
|
||||
from datetime import date, datetime, timedelta
|
||||
from enum import Enum
|
||||
from typing import Generator, List, Optional, Tuple, Union
|
||||
from typing import Generator, List, Tuple, Union
|
||||
|
||||
from . import dom
|
||||
|
||||
@ -779,7 +779,7 @@ class Timestamp:
|
||||
self.minute = minute
|
||||
self.repetition = repetition
|
||||
|
||||
def to_datetime(self) -> datetime:
|
||||
def to_datetime(self) -> Union[datetime, date]:
|
||||
if self.hour is not None:
|
||||
return datetime(self.year, self.month, self.day, self.hour, self.minute)
|
||||
else:
|
||||
@ -955,15 +955,11 @@ def parse_org_time_range(start, end) -> TimeRange:
|
||||
|
||||
|
||||
class OrgTime:
|
||||
def __init__(self, ts: Timestamp, end_time: Optional[Timestamp] = None):
|
||||
def __init__(self, ts: Timestamp, end_time: Union[Timestamp, None] = 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:
|
||||
@ -986,10 +982,6 @@ class OrgTime:
|
||||
else:
|
||||
return None
|
||||
|
||||
repetition = None
|
||||
if m.group("repetition"):
|
||||
repetition = m.group("repetition").strip()
|
||||
|
||||
if m.group("end_hour"):
|
||||
return OrgTime(
|
||||
Timestamp(
|
||||
@ -1000,7 +992,6 @@ class OrgTime:
|
||||
m.group("dow"),
|
||||
int(m.group("start_hour")),
|
||||
int(m.group("start_minute")),
|
||||
repetition=repetition,
|
||||
),
|
||||
Timestamp(
|
||||
active,
|
||||
@ -1022,7 +1013,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,
|
||||
repetition=repetition,
|
||||
m.group("repetition").strip() if m.group("repetition") else None,
|
||||
)
|
||||
)
|
||||
|
||||
@ -1035,7 +1026,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: Optional[Timestamp] = None) -> str:
|
||||
def timestamp_to_string(ts: Timestamp, end_time: Union[Timestamp, None] = None) -> str:
|
||||
date = "{year}-{month:02d}-{day:02d}".format(
|
||||
year=ts.year, month=ts.month, day=ts.day
|
||||
)
|
||||
@ -1056,7 +1047,7 @@ def timestamp_to_string(ts: Timestamp, end_time: Optional[Timestamp] = None) ->
|
||||
base=base, hour=end_time.hour, minute=end_time.minute
|
||||
)
|
||||
|
||||
if ts.repetition is not None:
|
||||
if ts.repetition:
|
||||
base = base + " " + ts.repetition
|
||||
|
||||
if ts.active:
|
||||
|
@ -19,6 +19,3 @@ 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,20 +418,6 @@ 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