Compare commits

...

2 Commits

Author SHA1 Message Date
Clemens Schwaighofer
ca0ab2d7d1 v0.24.2: TimestampString allows ZoneInfo object as zone name 2025-09-25 15:16:19 +09:00
Clemens Schwaighofer
38bae7fb46 TimestampStrings allows ZoneInfo object as time_zone parameter
So we can use pre-parsed data

Some tests for parsing settings, timestamp output
2025-09-25 15:14:40 +09:00
5 changed files with 14 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
# MARK: Project info # MARK: Project info
[project] [project]
name = "corelibs" name = "corelibs"
version = "0.24.1" version = "0.24.2"
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"

View File

@@ -23,11 +23,13 @@ class TimestampStrings:
TIME_ZONE: str = 'Asia/Tokyo' TIME_ZONE: str = 'Asia/Tokyo'
def __init__(self, time_zone: str | 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 self.time_zone = time_zone if time_zone is not None else self.TIME_ZONE
try: try:
self.timestamp_now_tz = datetime.now(ZoneInfo(self.time_zone)) self.timestamp_now_tz = datetime.now(
ZoneInfo(self.time_zone) if not isinstance(self.time_zone, ZoneInfo) 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.today = self.timestamp_now.strftime('%Y-%m-%d') self.today = self.timestamp_now.strftime('%Y-%m-%d')

View File

@@ -24,6 +24,7 @@ match_source_list=foo,bar
element_a=Static energy element_a=Static energy
element_b=123.5 element_b=123.5
element_c=True element_c=True
elemend_d=AB:CD;EF
email=foo@bar.com,other+bar-fee@domain-com.cp, email=foo@bar.com,other+bar-fee@domain-com.cp,
email_not_mandatory= email_not_mandatory=
email_bad=gii@bar.com email_bad=gii@bar.com

View File

@@ -4,10 +4,12 @@
Test for double byte format Test for double byte format
""" """
from zoneinfo import ZoneInfo
from corelibs.string_handling.timestamp_strings import TimestampStrings from corelibs.string_handling.timestamp_strings import TimestampStrings
def main(): def main():
"""test"""
ts = TimestampStrings() ts = TimestampStrings()
print(f"TS: {ts.timestamp_now}") print(f"TS: {ts.timestamp_now}")
@@ -16,6 +18,11 @@ def main():
except ValueError as e: except ValueError as e:
print(f"Value error: {e}") print(f"Value error: {e}")
ts = TimestampStrings("Europe/Vienna")
print(f"TZ: {ts.time_zone} -> TS: {ts.timestamp_now_tz}")
ts = TimestampStrings(ZoneInfo("Europe/Vienna"))
print(f"TZ: {ts.time_zone} -> TS: {ts.timestamp_now_tz}")
if __name__ == "__main__": if __name__ == "__main__":
main() main()

2
uv.lock generated
View File

@@ -53,7 +53,7 @@ wheels = [
[[package]] [[package]]
name = "corelibs" name = "corelibs"
version = "0.23.0" version = "0.24.1"
source = { editable = "." } source = { editable = "." }
dependencies = [ dependencies = [
{ name = "jmespath" }, { name = "jmespath" },