Fix state dt tz#508
Open
alexis-cousein wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I had noticed that when you input time/date "UTC TM" and "LCL TM" were always identical, and that when recovering time from GPS there was the expected gap between them, so I sanity checked some of the datetime timezone usage in the current code.
-The current date/time input routines are self-consistent but they store a datetime in shared_state that contains a timezone reference (to the local timezone the times were specified in), while when using the GPS everything is in UTC) .
-[bug] The status screen that displays "UTC TM" just expects the shared state to be in UTC.
Since other consumers of the shared state datetime might make the same mistake, I corrected this at both ends:
-When saving the shared state, always convert to a timezone-aware datetime that is UTC based, so that manual input time and GPS time will always behave similarly.
-Introduced a shared_state query routine utc_datetime in addition to local_datetime to avoid the ambiguous "datetime" (which just returns a valid datetime, but these can be in different timezones); the "TM UTC" visualisation now uses this.
Other bug:
-[bug] In set_time use of datetime.now() without explicit timezone to get "today's date" to combine it with the time that was input is just wrong: this yields a naive datetime of the time in the OS timezone; because "today's date in UTC" might be different from the date in the target timezone (which we force before setting it), that may lead us to set the datetime 24 hours off in some cases (which would incorrectly 'prime' the prefilled "date" in the next screen). There, we need to use datetime.now(timezone) to get a day that we *can * combine coherently with the one the user just filled in.
More cosmetic changes:
-replaced pytz.timezone("UTC") by the initialized singleton pytz.utc -- more readable and faster, no need to reconstruct this object time and again.
-gps_fake now explicitly uses a UTC-timezone-stamped datetime.now(pytz.utc) , just to avoid sending "naive" datetimes around.
-catalogs.py was extracting a naive datetime.now() --expressed in the OS timezone-- and just tagged on "UTC" to make a timezone-aware datetime. This is only correct if the OS timezone is UTC, and that is unnecessarily dangerous: datetime.now(pytz.utc) is guaranteed to give you the actual time expressed in UTC, and tagged as such.
-Renamed "GPS LST" ("the LaST time we got a GPS lock") in the status screen to "GPS LKT" (for "GPS LocKTime") to avoid confusion with Local Sidereal Time.