Exercise 1 solution from datetime import datetime, timezone, timedelta EPOCH = datetime(1970, 1, 1, tzinfo=timezone.utc) def to_seconds(v): a = abs(v) if a < 1e11: return v if a < 1e14: return v / 1e3 if a < 1e17: return v / 1e6 return v / 1e9 def to_dt(v): return EPOCH + timedelta(seconds=to_seconds(v)) stamps = [1_793_620_800, 1_793_620_800_500, 1_793_624_400_000, 1_793_706_000_250_000, 0, -86_400] for v in stamps: print(v, "->", to_dt(v).isoformat()) print("Elapsed:", to_dt(stamps[2]) - to_dt(stamps[1])) print("Elapsed:", to_dt(stamps[3]) - to_dt(stamps[0])) Output (run, and exactly as shown): 1793620800 -> 2026-11-02T12:00:00+00:00 1793620800500 -> 2026-11-02T12:00:00.500000+00:00 1793624400000 -> 2026-11-02T13:00:00+00:00 1793706000250000 -> 2026-11-03T11:40:00.250000+00:00 0 -> 1970-01-01T00:00:00+00:00 -86400 -> 1969-12-31T00:00:00+00:00 Elapsed: 0:59:59.500000 Elapsed: 23:40:00.250000 Explanation: values under 1e11 are seconds, under 1e14 milliseconds, under 1e17 microseconds, otherwise nanoseconds. These bounds cover dates from 1970 to well past the year 5000 in seconds, and the digit count of a current timestamp tells you its unit: 10 digits seconds, 13 milliseconds, 16 microseconds, 19 nanoseconds. Zero and negative values are seconds, and adding a timedelta to the epoch handles negatives on every platform, whereas fromtimestamp can fail on some systems for dates before 1970. Subtracting two aware datetimes gives the elapsed time directly.