diff --git a/servercom/implementations/circuitpy.py b/servercom/implementations/circuitpy.py index 34d9ca6..0512840 100644 --- a/servercom/implementations/circuitpy.py +++ b/servercom/implementations/circuitpy.py @@ -389,7 +389,7 @@ def get_status(self) -> GameStatus: resp_json = loads(resp[1]) if self.v: print(f"It is {resp_json['unix_time']} seconds since the epoch.") - return GameStatus(Time(resp_json['unix_time']), resp_json['status']['score'], resp_json['CubeServer_version']) + return GameStatus(Time(resp_json['2020_time']), resp_json['status']['score'], resp_json['CubeServer_version']) def sync_time(self) -> bool: """Syncs the current clock against the server""" diff --git a/servercom/timetools.py b/servercom/timetools.py index cad6a52..e6cd3c0 100644 --- a/servercom/timetools.py +++ b/servercom/timetools.py @@ -1,6 +1,8 @@ """Time Tools Some tools for dealing with times on microcontrollers (to a precision of 1 second) + +Note that epoch time is really time since 2020 if you're using CircuitPython """ from time import monotonic, struct_time @@ -24,6 +26,9 @@ EDT = -4 * TimeUnit.HOUR ) +# Offset to allow values to fit in 32-bit signed integers for CircuitPython: +HIGH_PRECISION_OFFSET = TimeUnit.YEAR * 50 # 50 years since epoch to make 0 2020-01-01 00:00:00 + class Time(Immutable): """Represents an instant in time based around a UNIX timestamp""" @@ -170,7 +175,7 @@ def __mod__(self, other: 'Time') -> 'Time': def __str__(self) -> str: if self.absolute: - return f"{self.seconds} seconds since 1 January 1970 00:00:00 UTC" + return f"{self.seconds} seconds since 1 January 2020 or 1970 00:00:00 UTC" return f"{self.seconds} seconds" def __repr__(self) -> str: