Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed22105ec8 | ||
|
|
7c5af588c7 |
@@ -1,7 +1,7 @@
|
|||||||
# MARK: Project info
|
# MARK: Project info
|
||||||
[project]
|
[project]
|
||||||
name = "corelibs"
|
name = "corelibs"
|
||||||
version = "0.24.3"
|
version = "0.24.4"
|
||||||
description = "Collection of utils for Python scripts"
|
description = "Collection of utils for Python scripts"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.13"
|
||||||
|
|||||||
@@ -25,13 +25,15 @@ class TimestampStrings:
|
|||||||
|
|
||||||
def __init__(self, time_zone: str | ZoneInfo | None = None):
|
def __init__(self, time_zone: str | ZoneInfo | None = None):
|
||||||
self.timestamp_now = datetime.now()
|
self.timestamp_now = datetime.now()
|
||||||
self.time_zone = time_zone if time_zone is not None else self.TIME_ZONE
|
# set time zone as string
|
||||||
|
time_zone = time_zone if time_zone is not None else self.TIME_ZONE
|
||||||
|
self.time_zone = str(time_zone) if not isinstance(time_zone, str) else time_zone
|
||||||
|
# set ZoneInfo type
|
||||||
try:
|
try:
|
||||||
self.timestamp_now_tz = datetime.now(
|
self.time_zone_zi = ZoneInfo(self.time_zone)
|
||||||
ZoneInfo(self.time_zone) if isinstance(self.time_zone, str) else self.time_zone
|
|
||||||
)
|
|
||||||
except ZoneInfoNotFoundError as e:
|
except ZoneInfoNotFoundError as e:
|
||||||
raise ValueError(f'Zone could not be loaded [{self.time_zone}]: {e}') from e
|
raise ValueError(f'Zone could not be loaded [{self.time_zone}]: {e}') from e
|
||||||
|
self.timestamp_now_tz = datetime.now(self.time_zone_zi)
|
||||||
self.today = self.timestamp_now.strftime('%Y-%m-%d')
|
self.today = self.timestamp_now.strftime('%Y-%m-%d')
|
||||||
self.timestamp = self.timestamp_now.strftime("%Y-%m-%d %H:%M:%S")
|
self.timestamp = self.timestamp_now.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
self.timestamp_tz = self.timestamp_now_tz.strftime("%Y-%m-%d %H:%M:%S %Z")
|
self.timestamp_tz = self.timestamp_now_tz.strftime("%Y-%m-%d %H:%M:%S %Z")
|
||||||
|
|||||||
@@ -144,8 +144,8 @@ class TestTimestampStrings:
|
|||||||
ts = TimestampStrings(time_zone=custom_tz_obj)
|
ts = TimestampStrings(time_zone=custom_tz_obj)
|
||||||
|
|
||||||
# The time_zone should be the ZoneInfo object itself
|
# The time_zone should be the ZoneInfo object itself
|
||||||
assert ts.time_zone is custom_tz_obj
|
assert ts.time_zone_zi is custom_tz_obj
|
||||||
assert isinstance(ts.time_zone, ZoneInfo)
|
assert isinstance(ts.time_zone_zi, ZoneInfo)
|
||||||
|
|
||||||
def test_zoneinfo_object_vs_string_equivalence(self):
|
def test_zoneinfo_object_vs_string_equivalence(self):
|
||||||
"""Test that ZoneInfo object and string produce equivalent results"""
|
"""Test that ZoneInfo object and string produce equivalent results"""
|
||||||
@@ -167,7 +167,7 @@ class TestTimestampStrings:
|
|||||||
|
|
||||||
# The time_zone attributes will be different types but represent the same timezone
|
# The time_zone attributes will be different types but represent the same timezone
|
||||||
assert str(ts_string.time_zone) == 'Europe/Paris'
|
assert str(ts_string.time_zone) == 'Europe/Paris'
|
||||||
assert isinstance(ts_zoneinfo.time_zone, ZoneInfo)
|
assert isinstance(ts_zoneinfo.time_zone_zi, ZoneInfo)
|
||||||
|
|
||||||
def test_edge_case_midnight(self):
|
def test_edge_case_midnight(self):
|
||||||
"""Test timestamp formatting at midnight"""
|
"""Test timestamp formatting at midnight"""
|
||||||
|
|||||||
Reference in New Issue
Block a user