v.0.8.3 main.py print_time_task on display
This commit is contained in:
@@ -4,13 +4,13 @@ import ntptime # type: ignore
|
||||
_UTC_OFFSET: int = 1 * 3600 # +1 or +2 hours for CEST, adjust for your timezone
|
||||
|
||||
|
||||
def local_time_with_offset():
|
||||
def local_time_with_offset() -> int:
|
||||
# Set timezone offset (in seconds)
|
||||
current_time = time.time() + _UTC_OFFSET
|
||||
return time.localtime(current_time)
|
||||
|
||||
|
||||
def get_datetime_string(format="full"):
|
||||
def get_datetime_string(format="full") -> str:
|
||||
"""
|
||||
Return date/time as string with different formats
|
||||
|
||||
@@ -39,7 +39,7 @@ def get_datetime_string(format="full"):
|
||||
return f"Ticks: {time.ticks_ms()} ms"
|
||||
|
||||
|
||||
def get_german_datetime():
|
||||
def get_german_datetime() -> str:
|
||||
"""Return German date and time"""
|
||||
try:
|
||||
year, month, day, hour, minute, second, weekday, yearday = (
|
||||
@@ -56,7 +56,7 @@ def get_german_datetime():
|
||||
return f"Zeit: {ticks} sek"
|
||||
|
||||
|
||||
def get_german_timestamp_short():
|
||||
def get_german_timestamp_short() -> str:
|
||||
"""Get German timestamp with short months (for Wokwi)"""
|
||||
ticks = time.ticks_ms()
|
||||
day = (ticks // 86400000) % 31 + 1
|
||||
@@ -83,7 +83,7 @@ def get_german_timestamp_short():
|
||||
return f"{day}.{month_name} {hour:02d}:{minute:02d}"
|
||||
|
||||
|
||||
def get_german_time_ticks():
|
||||
def get_german_time_ticks() -> str:
|
||||
"""Get German time using ticks (works in Wokwi)"""
|
||||
ticks = time.ticks_ms()
|
||||
|
||||
@@ -96,7 +96,7 @@ def get_german_time_ticks():
|
||||
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"
|
||||
|
||||
|
||||
def get_german_date_ticks():
|
||||
def get_german_date_ticks() -> str:
|
||||
"""Get German date using ticks"""
|
||||
ticks = time.ticks_ms()
|
||||
|
||||
@@ -125,7 +125,7 @@ def get_german_date_ticks():
|
||||
return f"{day:02d}.{month_name}.{str(year)[-2:]}"
|
||||
|
||||
|
||||
def sync_ntp_time():
|
||||
def sync_ntp_time() -> bool:
|
||||
try:
|
||||
print("Syncing time via NTP...")
|
||||
ntptime.settime() # Default uses pool.ntp.org
|
||||
|
||||
Reference in New Issue
Block a user