Class ServerTimeModule
Fetches the current UTC time from the Titipi server API and exposes it as UtcNow. Resynchronizes every 10 minutes; uses a cached value from PlayerPrefs on cold starts so the time is available immediately without waiting for the first network round-trip.
All timestamps are parsed as UTC (see UtcStyles); never with a bare DateTime.Parse,
which converts a Z-suffixed string to the device's local time. That silently shifts
UtcNow by the device's UTC offset when the API response carries a Z/offset
designator, and skews the cache staleness check on every cold start.
public static class ServerTimeModule
- Inheritance
-
ServerTimeModule
- Inherited Members
Properties
- IsInitialized
Whether the module has fetched (or loaded from cache) a valid server time.
- UtcNow
The current UTC time, derived by offsetting the last fetched server time by the elapsed real time since that fetch. Falls back to UtcNow and logs a warning if not yet initialized.
Initialization
- InitializeAsync()
Starts the server time sync loop. Immediately resolves from the PlayerPrefs cache if available, otherwise waits for the first successful network fetch before returning
true.
Events
- OnServerTimeReady
Fired when the server time is first available, either from cache or a successful network fetch.