Return the current offset to UTC in hours.
(
time: ModuleType = _time,
localtime: Callable[..., _time.struct_time] = _time.localtime)
| 518 | |
| 519 | |
| 520 | def utcoffset( |
| 521 | time: ModuleType = _time, |
| 522 | localtime: Callable[..., _time.struct_time] = _time.localtime) -> float: |
| 523 | """Return the current offset to UTC in hours.""" |
| 524 | # Use true division, not floor division: `time.timezone`/`time.altzone` |
| 525 | # are seconds *west* of UTC, and for a fractional-hour zone (e.g. |
| 526 | # India/Sri Lanka at UTC+5:30, seconds = -19800) floor-dividing rounds |
| 527 | # the magnitude *up* (-19800 // 3600 == -6) while the same fractional |
| 528 | # offset on the west-of-UTC side is unaffected (floor and truncation |
| 529 | # agree for positive dividends). Either kind of rounding is wrong for |
| 530 | # some fractional-hour zone or other -- `adjust_timestamp()` below is |
| 531 | # pure arithmetic on this value, so keep it exact instead. |
| 532 | if localtime().tm_isdst: |
| 533 | return time.altzone / 3600 |
| 534 | return time.timezone / 3600 |
| 535 | |
| 536 | |
| 537 | def adjust_timestamp(ts: float, offset: float, |
no outgoing calls