Skip to content

Commit

Permalink
add setters for DateRange and DateTimeRange
Browse files Browse the repository at this point in the history
  • Loading branch information
thrau committed Oct 14, 2023
1 parent 53560f7 commit 254b7b4
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions notion_objects/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,25 @@ def get(self, field: str, obj: dict) -> Tuple[Optional[datetime], Optional[datet

return start, end

def set(
self,
field: str,
value: Optional[Optional[Tuple[Union[datetime, str]], Optional[Union[datetime, str]]]],
obj: dict,
):
if value is None:
DateProperty.set_value(field, DateValue(start=None, end=None), obj)
return

start, end = value

if isinstance(start, str):
start = dateutil.parser.parse(value)
if isinstance(end, str):
end = dateutil.parser.parse(value)

DateProperty.set_value(field, DateValue(start=start, end=end, include_time=True), obj)


class DateRange(Property[Tuple[Optional[date], Optional[date]]]):
def get(self, field: str, obj: dict) -> Tuple[Optional[date], Optional[date]]:
Expand All @@ -400,6 +419,25 @@ def get(self, field: str, obj: dict) -> Tuple[Optional[date], Optional[date]]:

return start, end

def set(
self,
field: str,
value: Optional[Optional[Tuple[Union[date, str]], Optional[Union[date, str]]]],
obj: dict,
):
if value is None:
DateProperty.set_value(field, DateValue(start=None, end=None), obj)
return

start, end = value

if isinstance(start, str):
start = dateutil.parser.parse(value)
if isinstance(end, str):
end = dateutil.parser.parse(value)

DateProperty.set_value(field, DateValue(start=start, end=end), obj)


class DateRangeStart(Property[Optional[date]]):
def get(self, field: str, obj: dict) -> Optional[date]:
Expand Down

0 comments on commit 254b7b4

Please sign in to comment.