Skip to content

Fix state dt tz#508

Open
alexis-cousein wants to merge 2 commits into
brickbots:mainfrom
alexis-cousein:fix_state_dt_tz
Open

Fix state dt tz#508
alexis-cousein wants to merge 2 commits into
brickbots:mainfrom
alexis-cousein:fix_state_dt_tz

Conversation

@alexis-cousein

Copy link
Copy Markdown
Contributor

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.

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.

1 participant