Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

very minor fix in datetime_utils.parse_datetime_string #322

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ dcicutils
Change Log
----------

8.16.4
======
* dmichaels / 2024-11-17
* Very minor fix in datetime_utils.parse_datetime_string.


8.16.3
======
* dmichaels / 2024-11-08
Expand Down
8 changes: 6 additions & 2 deletions dcicutils/datetime_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ def parse_datetime_string(value: str) -> Optional[datetime]:
if tz_hours < 0 or tz_minutes < 0:
tz_hours, tz_minutes = get_local_timezone_hours_minutes()
try:
dt = datetime.strptime(value, "%Y-%m-%d %H:%M:%S")
try:
dt = datetime.strptime(value, "%Y-%m-%d %H:%M:%S")
except Exception:
dt = datetime.strptime(value, "%Y-%m-%d %H:%M:%S.%f")
tz = timezone(timedelta(hours=tz_hours, minutes=tz_minutes))
return dt.replace(tzinfo=tz)
except Exception:
Expand Down Expand Up @@ -214,11 +217,12 @@ def format_datetime(value: datetime,
if utc is True:
tz = timezone.utc
elif not isinstance(tz, timezone):
tz = get_local_timezone()
if tz is True:
notz = False
tz = get_local_timezone()
elif tz is False:
notz = True
tz = get_local_timezone()
if noseconds is True:
ms = False
value = value.astimezone(tz)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicutils"
version = "8.16.3"
version = "8.16.4"
description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources"
authors = ["4DN-DCIC Team <[email protected]>"]
license = "MIT"
Expand Down
Loading