"""Build time sanity checks — earliest/latest reasonable system clock values. Ported from net.i2p.time.BuildTime. """ import time from datetime import datetime, timezone # Hardcoded earliest reasonable time (update periodically) _EARLIEST_STR = "2025-05-26 12:00:00" _EARLIEST_LONG_MS = 1748217600 * 1000 # fallback if parse fails _YEARS_25_MS = 25 * 365 * 24 * 60 * 60 * 1000 def _parse_earliest() -> int: """Parse the earliest reasonable time string, return ms since epoch.""" try: dt = datetime.strptime(_EARLIEST_STR, "%Y-%m-%d %H:%M:%S").replace( tzinfo=timezone.utc ) return int(dt.timestamp() * 1000) except (ValueError, OverflowError): return _EARLIEST_LONG_MS _earliest_time = _parse_earliest() _latest_time = _earliest_time + _YEARS_25_MS # In Python context, we don't read JAR manifests — build time = earliest _build_time = _earliest_time class BuildTime: """Get build date sanity bounds for clock validation. In the Python port, we don't read JAR manifests, so build_time defaults to the hardcoded earliest time. """ @staticmethod def get_build_time() -> int: """Return build time in milliseconds since epoch.""" return _build_time @staticmethod def get_earliest_time() -> int: """Return the earliest reasonable time in ms since epoch.""" return _earliest_time @staticmethod def get_latest_time() -> int: """Return the latest reasonable time in ms since epoch.""" return _latest_time