Skip to content

Commit

Permalink
🎨 support time string for TimeAttribute. #43
Browse files Browse the repository at this point in the history
  • Loading branch information
perillaroc committed Sep 18, 2022
1 parent 0500e9d commit 856c50b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion takler/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ def add_repeat(self, r: RepeatBase):

# Time Attribute -----------------------------------------------------------

def add_time(self, time: datetime.time) -> TimeAttribute:
def add_time(self, time: Union[datetime.time, str]) -> TimeAttribute:
"""
Add a ``TimeAttribute`` to Node. Node can have multiply time attributes.
Expand Down
5 changes: 4 additions & 1 deletion takler/core/time_attr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from typing import Union

from .calendar import Calendar

Expand All @@ -16,7 +17,9 @@ class TimeAttribute:
free
if marked true, time attributes is ignored.
"""
def __init__(self, time: datetime.time):
def __init__(self, time: Union[datetime.time, str]):
if isinstance(time, str):
time = datetime.datetime.strptime(time, '%H:%M').time()
self.time: datetime.time = time
self.free: bool = False

Expand Down

0 comments on commit 856c50b

Please sign in to comment.