Skip to content

Commit

Permalink
Revert "fix: stripped time from meta date as datetime"
Browse files Browse the repository at this point in the history
This reverts commit 21c61f2.
  • Loading branch information
Guts committed Feb 9, 2024
1 parent 21c61f2 commit ac3309a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
4 changes: 1 addition & 3 deletions mkdocs_rss_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self):
self.src_date_created = self.src_date_updated = "git"
self.meta_datetime_format: Optional[str] = None
self.meta_default_timezone: str = "UTC"
self.meta_default_time: Optional[datetime.time] = None
self.meta_default_time: Optional[str] = None
# pages storage
self.pages_to_filter: list = []
# prepare output feeds
Expand Down Expand Up @@ -160,8 +160,6 @@ def on_config(self, config: config_options.Config) -> dict:
f"'{self.meta_default_time}' format doesn't match the expected "
f"format %H:%M. Trace: {err}"
)
else:
self.meta_default_time = datetime.min

if self.config.use_git:
logger.debug(
Expand Down
24 changes: 8 additions & 16 deletions mkdocs_rss_plugin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def get_file_dates(
source_date_update: str = "git",
meta_datetime_format: str = "%Y-%m-%d %H:%M",
meta_default_timezone: str = "UTC",
meta_default_time: Optional[datetime] = None,
meta_default_time: datetime = None,
) -> Tuple[datetime, datetime]:
"""Extract creation and update dates from page metadata (yaml frontmatter) or
git log for given file.
Expand All @@ -193,8 +193,6 @@ def get_file_dates(
"""
# empty vars
dt_created = dt_updated = None
if meta_default_time is None:
meta_default_time = self.meta_default_time = datetime.min

# if enabled, try to retrieve dates from page metadata
if not self.use_git or (
Expand Down Expand Up @@ -418,20 +416,14 @@ def get_date_from_meta(
try:
if isinstance(date_metatag_value, str):
out_date = datetime.strptime(date_metatag_value, meta_datetime_format)
# datetime being a subclass of date, the following elif order matters
# see: https://stackoverflow.com/a/68743663/2556577
elif isinstance(date_metatag_value, datetime):
# if datetime, use it directly
out_date = date_metatag_value
elif isinstance(date_metatag_value, date):
out_date = datetime.combine(
date=date_metatag_value, time=meta_default_time.time()
)
elif isinstance(date_metatag_value, (date, datetime)):
if isinstance(meta_default_time, datetime):
time_to_add = meta_default_time.time()
else:
time_to_add = datetime.min.time()
out_date = datetime.combine(date_metatag_value, time_to_add)
else:
logger.info(
f"Incompatible date type: {type(date_metatag_value)}. It must be: "
"date, datetime or str (complying with defined strftime format)."
)
logger.debug(f"Incompatible date type: {type(date_metatag_value)}")
return out_date
except ValueError as err:
logger.error(
Expand Down

0 comments on commit ac3309a

Please sign in to comment.