fix(waterdata): naive datetime filters shifted an hour across the DST boundary#307
Draft
thodson-usgs wants to merge 1 commit into
Draft
fix(waterdata): naive datetime filters shifted an hour across the DST boundary#307thodson-usgs wants to merge 1 commit into
thodson-usgs wants to merge 1 commit into
Conversation
…'s offset _format_api_dates froze `datetime.now().astimezone().tzinfo` (today's UTC offset) and applied it to every naive datetime input. A naive input on a date whose DST status differs from today was shifted by an hour: on an EDT (-0400) machine, time="2020-01-01 12:00:00" produced 2020-01-01T16:00:00Z, but January is EST (-0500) so the correct value is 17:00:00Z. This skewed the query window for get_continuous / get_field_measurements (time/begin/end) across DST boundaries. Use `parsed.astimezone()` to interpret a naive input in the system local zone with the DST rules for its own date, then convert to UTC. Inputs that already carry an explicit offset are unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
_format_api_datesresolved the local timezone once, as a frozen offset from "now":A fixed offset can't represent DST, so a naive datetime on a date whose DST status differs from today is shifted by an hour. Verified on an EDT (−04:00) machine:
This skews the query window for
get_continuous/get_field_measurements(time/begin/end) whenever the input date is in the other DST season.Fix
Interpret a naive input with
parsed.astimezone(), which presumes the system local zone and uses the DST rules for that input's own date, then convert to UTC. Inputs that already carry an explicit offset (Z/+HH:MM) are unchanged.Verification
16 existing date-formatting tests pass;
ruffclean.🤖 Generated with Claude Code