fix(time): flag ambiguous DST fall-back times in convert_time - #4781
Open
Nimra3261 wants to merge 1 commit into
Open
fix(time): flag ambiguous DST fall-back times in convert_time#4781Nimra3261 wants to merge 1 commit into
Nimra3261 wants to merge 1 commit into
Conversation
convert_time constructs the source datetime by attaching tzinfo directly to a naive year/month/day/hour/minute tuple. On the day a DST fall-back transition happens, the local wall-clock hour that repeats (e.g. 1:30 AM in America/New_York on the first Sunday of November) is ambiguous: two real, distinct moments share that same clock reading. Attaching tzinfo this way always resolves to fold=0, the earlier of the two, with nothing in the response indicating a choice was made. This adds a `note` field to TimeResult, populated only when the requested source time is ambiguous, explaining which of the two occurrences was used. Detection compares the tzinfo-attached datetime's UTC offset against the same wall-clock time under fold=1; a mismatch means two valid offsets exist for that reading. This is scoped to the ambiguous (fall-back) case only, distinct from and complementary to modelcontextprotocol#4719, which addresses the separate nonexistent (spring-forward gap) case -- confirmed via search that the two PRs don't overlap in what they change. 4 new tests covering: an ambiguous NY time, a non-ambiguous time on the same transition day, a timezone with no such transition on that date (to confirm the check is genuinely timezone-specific, not date-triggered), and a second timezone/month (Europe/Warsaw, October) to confirm the fix isn't hardcoded to one region's transition rules. All 42 existing plus new tests pass; pyright clean.
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.
Description
convert_timeconstructs the source datetime by attachingtzinfodirectly to a naive year/month/day/hour/minute tuple. On the day a DST fall-back transition happens, the local wall-clock hour that repeats (e.g. 1:30 AM in America/New_York on the first Sunday of November) is ambiguous: two real, distinct moments share that same clock reading. Attachingtzinfothis way always resolves tofold=0, the earlier of the two, with nothing in the response indicating a choice was made.Server Details
convert_timetool (adds an optionalnotefield toTimeResult)Motivation and Context
Reproduced directly:
convert_timereturns this as a confident, singular answer even though the requested wall-clock time was genuinely ambiguous. This adds anotefield toTimeResult, populated only when the requested source time is ambiguous, explaining which of the two occurrences was used -- so a caller (or the LLM relying on this tool) can see that the answer isn't the only valid one.Scoped relationship to #4719: I searched existing issues/PRs first. #4719 already fixes the nonexistent local time case (spring-forward gap, e.g. 2:30 AM on a day clocks jump 2:00→3:00) -- a different, more severe bug (that case has no valid answer at all, vs. this case having two valid answers). I confirmed the two PRs touch the same function but don't overlap in the specific lines/behavior changed. Happy to rebase on top of #4719 once it lands, or for a maintainer to ask me to fold this into that PR instead if preferred.
How Has This Been Tested?
uv run pytest-- 42 passed (38 existing + 4 new)pyright-- 0 errorsNew tests cover: an ambiguous NY time, a non-ambiguous time on the same transition day (note must stay unset), a timezone with no transition on that date (confirms the check is genuinely timezone-specific, not date-triggered), and a second timezone/month (Europe/Warsaw, October) to confirm the fix isn't hardcoded to the US transition rules.
Breaking Changes
None.
noteis a new optional field (defaults toNone); existing consumers reading the other fields are unaffected.Types of changes
Checklist
Additional context
Detection: compare the tzinfo-attached datetime's UTC offset against the same wall-clock reading under
fold=1; a mismatch means two valid offsets exist for that local time. This only fires for the source time (the one built from raw user input);target_timeis always derived via.astimezone(), which is unambiguous by construction.