mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Remove monotonic_time_coarse datetime helper (#104892)
This commit is contained in:
parent
3b5e498c30
commit
67039e0f26
@ -5,9 +5,7 @@ import bisect
|
||||
from contextlib import suppress
|
||||
import datetime as dt
|
||||
from functools import partial
|
||||
import platform
|
||||
import re
|
||||
import time
|
||||
from typing import Any
|
||||
import zoneinfo
|
||||
|
||||
@ -16,7 +14,6 @@ import ciso8601
|
||||
DATE_STR_FORMAT = "%Y-%m-%d"
|
||||
UTC = dt.UTC
|
||||
DEFAULT_TIME_ZONE: dt.tzinfo = dt.UTC
|
||||
CLOCK_MONOTONIC_COARSE = 6
|
||||
|
||||
# EPOCHORDINAL is not exposed as a constant
|
||||
# https://github.com/python/cpython/blob/3.10/Lib/zoneinfo/_zoneinfo.py#L12
|
||||
@ -476,29 +473,3 @@ def _datetime_ambiguous(dattim: dt.datetime) -> bool:
|
||||
assert dattim.tzinfo is not None
|
||||
opposite_fold = dattim.replace(fold=not dattim.fold)
|
||||
return _datetime_exists(dattim) and dattim.utcoffset() != opposite_fold.utcoffset()
|
||||
|
||||
|
||||
def __gen_monotonic_time_coarse() -> partial[float]:
|
||||
"""Return a function that provides monotonic time in seconds.
|
||||
|
||||
This is the coarse version of time_monotonic, which is faster but less accurate.
|
||||
|
||||
Since many arm64 and 32-bit platforms don't support VDSO with time.monotonic
|
||||
because of errata, we can't rely on the kernel to provide a fast
|
||||
monotonic time.
|
||||
|
||||
https://lore.kernel.org/lkml/20170404171826.25030-1-marc.zyngier@arm.com/
|
||||
"""
|
||||
# We use a partial here since its implementation is in native code
|
||||
# which allows us to avoid the overhead of the global lookup
|
||||
# of CLOCK_MONOTONIC_COARSE.
|
||||
return partial(time.clock_gettime, CLOCK_MONOTONIC_COARSE)
|
||||
|
||||
|
||||
monotonic_time_coarse = time.monotonic
|
||||
with suppress(Exception):
|
||||
if (
|
||||
platform.system() == "Linux"
|
||||
and abs(time.monotonic() - __gen_monotonic_time_coarse()()) < 1
|
||||
):
|
||||
monotonic_time_coarse = __gen_monotonic_time_coarse()
|
||||
|
@ -2,7 +2,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime, timedelta
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
@ -737,8 +736,3 @@ def test_find_next_time_expression_tenth_second_pattern_does_not_drift_entering_
|
||||
assert (next_target - prev_target).total_seconds() == 60
|
||||
assert next_target.second == 10
|
||||
prev_target = next_target
|
||||
|
||||
|
||||
def test_monotonic_time_coarse() -> None:
|
||||
"""Test monotonic time coarse."""
|
||||
assert abs(time.monotonic() - dt_util.monotonic_time_coarse()) < 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user