Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 6de6767

Browse files
committed
Use an enum for DST status
1 parent d5c21c0 commit 6de6767

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/wwvb/__init__.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,16 @@ def _hamming_parity(value: int) -> int:
323323
]
324324

325325

326+
@enum.unique
327+
class DstStatus(enum.IntEnum):
328+
"""Constants that describe the DST status of a minute"""
329+
330+
DST_NOT_IN_EFFECT = 0b00
331+
DST_STARTS_TODAY = 0b01
332+
DST_ENDS_TODAY = 0b10
333+
DST_IN_EFFECT = 0b11
334+
335+
326336
class _WWVBMinute(NamedTuple):
327337
"""Uniquely identifies a minute of time in the WWVB system.
328338
@@ -341,7 +351,7 @@ class _WWVBMinute(NamedTuple):
341351
min: int
342352
"""Minute of hour"""
343353

344-
dst: int
354+
dst: DstStatus
345355
"""2-bit DST code """
346356

347357
ut1: int
@@ -368,16 +378,13 @@ def __new__( # noqa: PYI034
368378
days: int,
369379
hour: int,
370380
minute: int,
371-
dst: int | None = None,
381+
dst: DstStatus | int | None = None,
372382
ut1: int | None = None,
373383
ls: bool | None = None,
374384
ly: bool | None = None,
375385
) -> WWVBMinute:
376386
"""Construct a WWVBMinute"""
377-
if dst is None:
378-
dst = cls.get_dst(year, days)
379-
if dst not in (0, 1, 2, 3):
380-
raise ValueError("dst value should be 0..3")
387+
dst = cls.get_dst(year, days) if dst is None else DstStatus(dst)
381388
if ut1 is None and ls is None:
382389
ut1, ls = cls._get_dut1_info(year, days)
383390
elif ut1 is None or ls is None:
@@ -407,13 +414,13 @@ def full_year(cls, year: int) -> int:
407414
return year
408415

409416
@staticmethod
410-
def get_dst(year: int, days: int) -> int:
417+
def get_dst(year: int, days: int) -> DstStatus:
411418
"""Get the 2-bit WWVB DST value for the given day"""
412419
d0 = datetime.datetime(year, 1, 1, tzinfo=datetime.timezone.utc) + datetime.timedelta(days - 1)
413420
d1 = d0 + datetime.timedelta(1)
414421
dst0 = isdst(d0)
415422
dst1 = isdst(d1)
416-
return dst1 * 2 + dst0
423+
return DstStatus(dst1 * 2 + dst0)
417424

418425
def __str__(self) -> str:
419426
"""Implement str()"""

0 commit comments

Comments
 (0)