-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to set default_timezone #133
- Loading branch information
Showing
6 changed files
with
163 additions
and
22 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#! python3 # noqa: E265 | ||
|
||
|
||
""" | ||
Manage timezones for pages date(time)s using zoneinfo module, added in Python 3.9. | ||
""" | ||
|
||
# ############################################################################ | ||
# ########## Libraries ############# | ||
# ################################## | ||
|
||
# standard library | ||
import logging | ||
from datetime import datetime | ||
from functools import lru_cache | ||
|
||
# ############################################################################ | ||
# ########## Globals ############# | ||
# ################################ | ||
|
||
|
||
logger = logging.getLogger("mkdocs.mkdocs_rss_plugin") | ||
|
||
|
||
# ############################################################################ | ||
# ########## Functions ########### | ||
# ################################ | ||
|
||
|
||
@lru_cache(typed=True) | ||
def set_datetime_zoneinfo( | ||
input_datetime: datetime, config_timezone: str = None | ||
) -> datetime: | ||
"""_summary_ | ||
:param input_datetime: _description_ | ||
:type input_datetime: datetime | ||
:param config_timezone: _description_ | ||
:type config_timezone: str | ||
:return: _description_ | ||
:rtype: datetime | ||
""" | ||
pass |
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,51 @@ | ||
#! python3 # noqa: E265 | ||
|
||
|
||
""" | ||
Manage timezones for pages date(time)s using zoneinfo module, added in Python 3.9. | ||
""" | ||
|
||
# ############################################################################ | ||
# ########## Libraries ############# | ||
# ################################## | ||
|
||
# standard library | ||
import logging | ||
from datetime import datetime, timezone | ||
from zoneinfo import ZoneInfo | ||
|
||
# ############################################################################ | ||
# ########## Globals ############# | ||
# ################################ | ||
|
||
|
||
logger = logging.getLogger("mkdocs.mkdocs_rss_plugin") | ||
|
||
|
||
# ############################################################################ | ||
# ########## Functions ########### | ||
# ################################ | ||
|
||
|
||
def set_datetime_zoneinfo( | ||
input_datetime: datetime, config_timezone: str = "UTC" | ||
) -> datetime: | ||
"""Apply timezone to a naive datetime. | ||
:param input_datetime: offset-naive datetime | ||
:type input_datetime: datetime | ||
:param config_timezone: name of timezone as registered in IANA database, | ||
defaults to "UTC". Example : Europe/Paris. | ||
:type config_timezone: str, optional | ||
:return: offset-aware datetime | ||
:rtype: datetime | ||
""" | ||
if input_datetime.tzinfo: | ||
return input_datetime | ||
elif not config_timezone: | ||
return input_datetime.replace(tzinfo=timezone.utc) | ||
else: | ||
config_tz = ZoneInfo(config_timezone) | ||
return input_datetime.replace(tzinfo=config_tz) |
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