Skip to content

Commit

Permalink
Merge pull request #322 from 4dn-dcic/dmichaels-20241117-minor-fixes
Browse files Browse the repository at this point in the history
very minor fix in datetime_utils.parse_datetime_string
  • Loading branch information
dmichaels-harvard authored Nov 19, 2024
2 parents ebd157a + 3ec465a commit d1dbd66
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
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

0 comments on commit d1dbd66

Please sign in to comment.