Compare commits
No commits in common. "6b8b4de21e8327fbbfb0b986d3f6e2aa913e44af" and "63bb1e67e0e312c35f0d0c85269330da9f3e8d28" have entirely different histories.
6b8b4de21e
...
63bb1e67e0
@ -8,7 +8,7 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
from datetime import date, datetime, timedelta
|
from datetime import date, datetime, timedelta
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Generator, List, Optional, Tuple, Union
|
from typing import Generator, List, Tuple, Union
|
||||||
|
|
||||||
from . import dom
|
from . import dom
|
||||||
|
|
||||||
@ -779,7 +779,7 @@ class Timestamp:
|
|||||||
self.minute = minute
|
self.minute = minute
|
||||||
self.repetition = repetition
|
self.repetition = repetition
|
||||||
|
|
||||||
def to_datetime(self) -> datetime:
|
def to_datetime(self) -> Union[datetime, date]:
|
||||||
if self.hour is not None:
|
if self.hour is not None:
|
||||||
return datetime(self.year, self.month, self.day, self.hour, self.minute)
|
return datetime(self.year, self.month, self.day, self.hour, self.minute)
|
||||||
else:
|
else:
|
||||||
@ -955,15 +955,11 @@ def parse_org_time_range(start, end) -> TimeRange:
|
|||||||
|
|
||||||
|
|
||||||
class OrgTime:
|
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
|
assert ts is not None
|
||||||
self.time = ts
|
self.time = ts
|
||||||
self.end_time = end_time
|
self.end_time = end_time
|
||||||
|
|
||||||
@property
|
|
||||||
def repetition(self):
|
|
||||||
return self.time.repetition
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def duration(self):
|
def duration(self):
|
||||||
if self.end_time is None:
|
if self.end_time is None:
|
||||||
@ -986,10 +982,6 @@ class OrgTime:
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
repetition = None
|
|
||||||
if m.group("repetition"):
|
|
||||||
repetition = m.group("repetition").strip()
|
|
||||||
|
|
||||||
if m.group("end_hour"):
|
if m.group("end_hour"):
|
||||||
return OrgTime(
|
return OrgTime(
|
||||||
Timestamp(
|
Timestamp(
|
||||||
@ -1000,7 +992,6 @@ class OrgTime:
|
|||||||
m.group("dow"),
|
m.group("dow"),
|
||||||
int(m.group("start_hour")),
|
int(m.group("start_hour")),
|
||||||
int(m.group("start_minute")),
|
int(m.group("start_minute")),
|
||||||
repetition=repetition,
|
|
||||||
),
|
),
|
||||||
Timestamp(
|
Timestamp(
|
||||||
active,
|
active,
|
||||||
@ -1022,7 +1013,7 @@ class OrgTime:
|
|||||||
m.group("dow"),
|
m.group("dow"),
|
||||||
int(m.group("start_hour")) if m.group("start_hour") else None,
|
int(m.group("start_hour")) if m.group("start_hour") else None,
|
||||||
int(m.group("start_minute")) if m.group("start_minute") 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()
|
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(
|
date = "{year}-{month:02d}-{day:02d}".format(
|
||||||
year=ts.year, month=ts.month, day=ts.day
|
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
|
base=base, hour=end_time.hour, minute=end_time.minute
|
||||||
)
|
)
|
||||||
|
|
||||||
if ts.repetition is not None:
|
if ts.repetition:
|
||||||
base = base + " " + ts.repetition
|
base = base + " " + ts.repetition
|
||||||
|
|
||||||
if ts.active:
|
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 for time range
|
||||||
SCHEDULED: <2020-12-15 Mar 00:05-00:10>
|
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),
|
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):
|
def test_update_info_file_05(self):
|
||||||
with open(os.path.join(DIR, "05-dates.org")) as f:
|
with open(os.path.join(DIR, "05-dates.org")) as f:
|
||||||
orig = f.read()
|
orig = f.read()
|
||||||
|
Loading…
Reference in New Issue
Block a user