dycw-utilities 0.131.11__py3-none-any.whl → 0.131.13__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
utilities/whenever2.py CHANGED
@@ -16,7 +16,9 @@ from whenever import (
16
16
  ZonedDateTime,
17
17
  )
18
18
 
19
+ from utilities.datetime import maybe_sub_pct_y
19
20
  from utilities.sentinel import Sentinel, sentinel
21
+ from utilities.tzlocal import LOCAL_TIME_ZONE, LOCAL_TIME_ZONE_NAME
20
22
  from utilities.zoneinfo import UTC, get_time_zone_name
21
23
 
22
24
  if TYPE_CHECKING:
@@ -72,6 +74,15 @@ WEEK = DateDelta(weeks=1)
72
74
  ##
73
75
 
74
76
 
77
+ def format_compact(datetime: ZonedDateTime, /) -> str:
78
+ """Convert a zoned datetime to the local time zone, then format."""
79
+ py_datetime = datetime.round().to_tz(LOCAL_TIME_ZONE_NAME).to_plain().py_datetime()
80
+ return py_datetime.strftime(maybe_sub_pct_y("%Y%m%dT%H%M%S"))
81
+
82
+
83
+ ##
84
+
85
+
75
86
  def from_timestamp(i: float, /, *, time_zone: TimeZoneLike = UTC) -> ZonedDateTime:
76
87
  """Get a zoned datetime from a timestamp."""
77
88
  return ZonedDateTime.from_timestamp(i, tz=get_time_zone_name(time_zone))
@@ -100,7 +111,7 @@ NOW_UTC = get_now(time_zone=UTC)
100
111
 
101
112
  def get_now_local() -> ZonedDateTime:
102
113
  """Get the current local time."""
103
- return get_now(time_zone="local")
114
+ return get_now(time_zone=LOCAL_TIME_ZONE)
104
115
 
105
116
 
106
117
  NOW_LOCAL = get_now_local()
@@ -119,7 +130,7 @@ TODAY_UTC = get_today(time_zone=UTC)
119
130
 
120
131
  def get_today_local() -> Date:
121
132
  """Get the current, timezone-aware local date."""
122
- return get_today(time_zone="local")
133
+ return get_today(time_zone=LOCAL_TIME_ZONE)
123
134
 
124
135
 
125
136
  TODAY_LOCAL = get_today_local()
@@ -255,6 +266,8 @@ __all__ = [
255
266
  "ZONED_DATE_TIME_MAX",
256
267
  "ZONED_DATE_TIME_MIN",
257
268
  "WheneverLogRecord",
269
+ "format_compact",
270
+ "format_compact",
258
271
  "from_timestamp",
259
272
  "from_timestamp_millis",
260
273
  "from_timestamp_nanos",
utilities/zoneinfo.py CHANGED
@@ -5,7 +5,7 @@ from dataclasses import dataclass
5
5
  from typing import TYPE_CHECKING, assert_never, cast, override
6
6
  from zoneinfo import ZoneInfo
7
7
 
8
- from utilities.tzlocal import get_local_time_zone
8
+ from utilities.tzlocal import LOCAL_TIME_ZONE
9
9
 
10
10
  if TYPE_CHECKING:
11
11
  from utilities.types import TimeZone, TimeZoneLike
@@ -23,7 +23,7 @@ def ensure_time_zone(obj: TimeZoneLike, /) -> ZoneInfo:
23
23
  case ZoneInfo() as zone_info:
24
24
  return zone_info
25
25
  case "local":
26
- return get_local_time_zone()
26
+ return LOCAL_TIME_ZONE
27
27
  case str() as key:
28
28
  return ZoneInfo(key)
29
29
  case dt.tzinfo() as tzinfo: