Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions generated/nidaqmx/_time.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from datetime import datetime as std_datetime, timezone, tzinfo as dt_tzinfo
from datetime import timezone, tzinfo as dt_tzinfo
from zoneinfo import ZoneInfo

from hightime import datetime as ht_datetime
Expand All @@ -9,8 +9,8 @@

# theoretically the same as astimezone(), but with support for dates before 1970
def _convert_to_desired_timezone(
expected_time_utc: std_datetime | ht_datetime, tzinfo: dt_tzinfo | None = None
) -> std_datetime | ht_datetime:
expected_time_utc: ht_datetime, tzinfo: dt_tzinfo | None = None
) -> ht_datetime:
# if timezone matches, no need to do conversion
if expected_time_utc.tzinfo is tzinfo:
return expected_time_utc
Expand All @@ -23,12 +23,13 @@ def _convert_to_desired_timezone(
if isinstance(tzinfo, ZoneInfo):
localized_time = expected_time_utc.replace(tzinfo=tzinfo)
desired_expected_time = tzinfo.fromutc(localized_time)
return desired_expected_time
return desired_expected_time # type: ignore[return-value] # https://github.com/ni/nidaqmx-python/issues/860

# if the tzinfo passed in is a timedelta function, then we don't need to consider daylight savings # noqa: W505 - doc line too long (102 > 100 characters) (auto-generated noqa)
elif tzinfo.utcoffset(None) is not None:
current_time_utc = ht_datetime.now(timezone.utc)
desired_timezone_offset = current_time_utc.astimezone(tz=tzinfo).utcoffset()
assert desired_timezone_offset is not None
desired_expected_time = expected_time_utc + desired_timezone_offset
new_datetime = desired_expected_time.replace(tzinfo=tzinfo)
return new_datetime
Expand Down
14 changes: 8 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ build-backend = "poetry.core.masonry.api"
files = "generated/,tests/"
check_untyped_defs = true
namespace_packages = true
plugins = "numpy.typing.mypy_plugin"
warn_redundant_casts = true
warn_unreachable = true
warn_unused_configs = true
Expand All @@ -182,8 +181,6 @@ module = [
# https://github.com/briancurtin/deprecation/issues/56 - Add type information (PEP 561)
"deprecation.*",
"grpc.experimental.*",
# https://github.com/ni/hightime/issues/4 - Add type annotations
"hightime.*",
"importlib_metadata",
"mako.*",
"nidaqmx.*",
Expand Down
9 changes: 5 additions & 4 deletions src/handwritten/_time.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from datetime import datetime as std_datetime, timezone, tzinfo as dt_tzinfo
from datetime import timezone, tzinfo as dt_tzinfo
from zoneinfo import ZoneInfo

from hightime import datetime as ht_datetime
Expand All @@ -9,8 +9,8 @@

# theoretically the same as astimezone(), but with support for dates before 1970
def _convert_to_desired_timezone(
expected_time_utc: std_datetime | ht_datetime, tzinfo: dt_tzinfo | None = None
) -> std_datetime | ht_datetime:
expected_time_utc: ht_datetime, tzinfo: dt_tzinfo | None = None
) -> ht_datetime:
# if timezone matches, no need to do conversion
if expected_time_utc.tzinfo is tzinfo:
return expected_time_utc
Expand All @@ -23,12 +23,13 @@ def _convert_to_desired_timezone(
if isinstance(tzinfo, ZoneInfo):
localized_time = expected_time_utc.replace(tzinfo=tzinfo)
desired_expected_time = tzinfo.fromutc(localized_time)
return desired_expected_time
return desired_expected_time # type: ignore[return-value] # https://github.com/ni/nidaqmx-python/issues/860

# if the tzinfo passed in is a timedelta function, then we don't need to consider daylight savings # noqa: W505 - doc line too long (102 > 100 characters) (auto-generated noqa)
elif tzinfo.utcoffset(None) is not None:
current_time_utc = ht_datetime.now(timezone.utc)
desired_timezone_offset = current_time_utc.astimezone(tz=tzinfo).utcoffset()
assert desired_timezone_offset is not None
desired_expected_time = expected_time_utc + desired_timezone_offset
new_datetime = desired_expected_time.replace(tzinfo=tzinfo)
return new_datetime
Expand Down
3 changes: 2 additions & 1 deletion tests/component/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from datetime import timezone

from hightime import datetime as ht_datetime
from nitypes.time.typing import AnyDateTime


def _is_timestamp_close_to_now(timestamp: ht_datetime, tolerance_seconds: float = 1.0) -> bool:
def _is_timestamp_close_to_now(timestamp: AnyDateTime, tolerance_seconds: float = 1.0) -> bool:
current_time = ht_datetime.now(timezone.utc)
time_diff = abs((timestamp - current_time).total_seconds())
return time_diff <= tolerance_seconds
Loading