66# SPDX-License-Identifier: GPL-3.0-only
77from __future__ import annotations
88
9+ import datetime
910import functools
10- import time
1111from tkinter import Canvas , TclError , Tk
1212from typing import TYPE_CHECKING , Any
1313
@@ -59,31 +59,29 @@ def validate_colors(ctx: Any, param: Any, value: str) -> list[str]: # noqa: ARG
5959 metavar = "COLORS" ,
6060 help = "2, 3, 4, or 6 Tk color values" ,
6161)
62- @click .option ("--size" , default = 48 )
63- @click .option ("--min-size" , default = None )
62+ @click .option ("--size" , default = 48 , help = "initial size in pixels" )
63+ @click .option ("--min-size" , default = None , type = int , help = "minimum size in pixels (default: same as initial size)" )
6464def main (colors : list [str ], size : int , min_size : int | None ) -> None : # noqa: PLR0915
6565 """Visualize the WWVB signal in realtime"""
6666 if min_size is None :
6767 min_size = size
6868
69- def deadline_ms (deadline : float ) -> int :
69+ def deadline_ms (deadline : datetime . datetime ) -> int :
7070 """Compute the number of ms until a deadline"""
71- now = time . time ( )
72- return int (max (0 , deadline - now ) * 1000 )
71+ now = datetime . datetime . now ( datetime . timezone . utc )
72+ return int (max (0 , ( deadline - now ). total_seconds () ) * 1000 )
7373
74- def wwvbtick () -> Generator [tuple [float , wwvb .AmplitudeModulation ], None , None ]:
74+ def wwvbtick () -> Generator [tuple [datetime . datetime , wwvb .AmplitudeModulation ]]:
7575 """Yield consecutive values of the WWVB amplitude signal, going from minute to minute"""
76- timestamp = time . time () // 60 * 60
76+ timestamp = datetime . datetime . now ( datetime . timezone . utc ). replace ( second = 0 , microsecond = 0 )
7777
7878 while True :
79- tt = time .gmtime (timestamp )
80- key = tt .tm_year , tt .tm_yday , tt .tm_hour , tt .tm_min
81- timecode = wwvb .WWVBMinuteIERS (* key ).as_timecode ()
79+ timecode = wwvb .WWVBMinuteIERS .from_datetime (timestamp ).as_timecode ()
8280 for i , code in enumerate (timecode .am ):
83- yield timestamp + i , code
84- timestamp = timestamp + 60
81+ yield timestamp + datetime . timedelta ( seconds = i ) , code
82+ timestamp = timestamp + datetime . timedelta ( seconds = 60 )
8583
86- def wwvbsmarttick () -> Generator [tuple [float , wwvb .AmplitudeModulation ], None , None ]:
84+ def wwvbsmarttick () -> Generator [tuple [datetime . datetime , wwvb .AmplitudeModulation ]]:
8785 """Yield consecutive values of the WWVB amplitude signal
8886
8987 .. but deal with time progressing unexpectedly, such as when the
@@ -94,10 +92,10 @@ def wwvbsmarttick() -> Generator[tuple[float, wwvb.AmplitudeModulation], None, N
9492 """
9593 while True :
9694 for stamp , code in wwvbtick ():
97- now = time . time ( )
98- if stamp < now - 60 :
95+ now = datetime . datetime . now ( datetime . timezone . utc )
96+ if stamp < now - datetime . timedelta ( seconds = 60 ) :
9997 break
100- if stamp < now - 1 :
98+ if stamp < now - datetime . timedelta ( seconds = 1 ) :
10199 continue
102100 yield stamp , code
103101
@@ -137,7 +135,7 @@ def controller_func() -> Generator[int]:
137135 yield deadline_ms (stamp )
138136 led_on (code )
139137 app .update ()
140- yield deadline_ms (stamp + 0.2 + 0.3 * int (code ))
138+ yield deadline_ms (stamp + datetime . timedelta ( seconds = 0.2 + 0.3 * int (code ) ))
141139 led_off (code )
142140 app .update ()
143141
0 commit comments