-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix all-day events entered in Google Cal - Reduce duplication with Gt…
…asks Fixes #126
- Loading branch information
1 parent
9f70769
commit a6b5159
Showing
6 changed files
with
62 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from __future__ import annotations | ||
|
||
import datetime | ||
from typing import TYPE_CHECKING, cast | ||
|
||
import dateutil | ||
from bubop import assume_local_tz_if_none | ||
|
||
if TYPE_CHECKING: | ||
from syncall.types import GoogleDateT | ||
|
||
|
||
def parse_google_datetime(dt: GoogleDateT) -> datetime.datetime: | ||
"""Parse datetime given in format(s) returned by the Google API: | ||
- string with ('T', 'Z' separators). | ||
- (dateTime, timeZone) dictionary | ||
- datetime object | ||
The output datetime is always in local timezone. | ||
""" | ||
if isinstance(dt, str): | ||
dt_dt = dateutil.parser.parse(dt) # type: ignore | ||
return parse_google_datetime(dt_dt) | ||
|
||
if isinstance(dt, dict): | ||
for key in "dateTime", "date": | ||
if key in dt: | ||
date_time = cast(str, dt.get(key)) | ||
break | ||
else: | ||
raise RuntimeError(f"Invalid structure dict: {dt}") | ||
|
||
return parse_google_datetime(date_time) | ||
|
||
if isinstance(dt, datetime.datetime): | ||
return assume_local_tz_if_none(dt) | ||
|
||
raise TypeError( | ||
f"Unexpected type of a given date item, type: {type(dt)}, contents: {dt}", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters