Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System (or "local") time zone implementation for tz_local that can handle DST and time zone transitions and is based on the time module #14

Open
wants to merge 7 commits into
base: add-fold
Choose a base branch
from

Conversation

blubberdiblub
Copy link

This addresses one of Arie Bovenberg's complaints in #12 regarding the tz_local attribute of heliclockter. It provides an own implementation that doesn't need the tzlocal module (but can optionally utilize it to return a more useful value from the .key attribute if it happens to be installed) and is properly sensitive to TZ and time.tzset().

Note that this pull request depends on the fold attribute added in #13 which hasn't been merged yet (and as such is built on top of the commits from the add-fold branch). So please don't consider merging this before the other pull request has been merged and this one properly rebased against the resulting master.

It's also fine to reject the pull request, if you don't want or need this in heliclockter.

Note that this also brings along a test suite with extensive checks against dates and times, many of which are possible edge cases. The test scaffolding could also be utilized for other existing tests. E.g. in instantiation_test.py it says "We cannot test datetime_local as the expected hour will vary on the system testing", which used to be true, but with the tzset, systemtz and welldefined_timezone fixtures it's now possible to test it as well. For that, it'd likely be desirable to move the fixtures to a more central place, such as conftest.py, which would make them available to all tests.

p-nilsson and others added 7 commits January 16, 2024 10:58
We need to adjust `sys.path` to ensure the right package is tested
at all times (rather than a potentially installed one).

conftest.py is the ideal place to do this as pytest ensures a file
with this name is imported first (you can also place pytest hooks
there).

At the same time this allows us to get rid of the absolute imports
from tests.shared and use more robust relative imports instead.
`SystemTZ` is a subclass of `datetime.tzinfo` and is API compatible with
`ZoneInfo`. Instances of the class represent the time zone the system
(or the application) is configured to.

It implements this via delegating to `time.*` functionality and is
sensitive to and supports changing the time zone via setting the `TZ`
environment variable and subsequently calling `time.tzset()` on systems
that provide this function (not Windows).

We also add a test suite with an extensive list of datetimes lots of
which are potentially tricky corner cases to ensure that the
implementation is not faulty.
@p-nilsson
Copy link
Contributor

@blubberdiblub, thanks for your contribution! Do you mind rebasing this PR, then I will try to have a look at it

@DanielNoord DanielNoord deleted the branch channable:add-fold March 26, 2024 11:57
@DanielNoord DanielNoord reopened this Mar 26, 2024
@DanielNoord
Copy link

Sorry, me removing the add-fold branch automatically closed this branch. @blubberdiblub could you rebase and point this to master so we can remove the add-fold branch without closing your PR? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants