Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion servercom/implementations/circuitpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
7 changes: 6 additions & 1 deletion servercom/timetools.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"""

Expand Down Expand Up @@ -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:
Expand Down