Skip to content

feat: Improve POSIX time zone string generation#4087

Merged
jamesarich merged 6 commits into
mainfrom
fix/posix-tz-strings
Dec 28, 2025
Merged

feat: Improve POSIX time zone string generation#4087
jamesarich merged 6 commits into
mainfrom
fix/posix-tz-strings

Conversation

@jamesarich

Copy link
Copy Markdown
Collaborator

This refactors the toPosixString() extension function for ZoneId to more accurately generate POSIX-compliant time zone strings, especially for time zones with daylight saving time transitions.

Key changes include:

  • Rewriting the logic to use zone.rules.transitionRules for determining standard and daylight saving time transitions, instead of relying on nextTransition.
  • Improving the calculation of transition rule strings (start/end of DST).
  • Correcting the POSIX offset formatting.
  • Updating and correcting test cases for various time zones to reflect the improved accuracy.

uses detailed examples from and resolves #3705

This commit refactors the `toPosixString()` extension function for `ZoneId` to more accurately generate POSIX-compliant time zone strings, especially for time zones with daylight saving time transitions.

Key changes include:
- Rewriting the logic to use `zone.rules.transitionRules` for determining standard and daylight saving time transitions, instead of relying on `nextTransition`.
- Improving the calculation of transition rule strings (start/end of DST).
- Correcting the POSIX offset formatting.
- Updating and correcting test cases for various time zones to reflect the improved accuracy.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the toPosixString() extension function for ZoneId to improve accuracy and correctness when generating POSIX-compliant time zone strings, particularly for zones with daylight saving time transitions.

Key changes:

  • Replaced the previous nextTransition-based approach with transitionRules-based logic for more reliable DST detection
  • Improved transition rule calculation to correctly handle occurrence weeks and wall time conversions
  • Enhanced offset formatting with proper handling of negative fractional hour offsets

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
core/ui/src/main/kotlin/org/meshtastic/core/ui/timezone/ZoneIdExtensions.kt Complete rewrite of toPosixString() logic using transitionRules instead of nextTransition; added new helper functions for formatting abbreviations, offsets, and transition rules; improved wall time calculation for different time definitions
core/ui/src/test/kotlin/org/meshtastic/core/ui/timezone/ZoneIdExtensionsTest.kt Updated expected POSIX strings to reflect corrected calculations: week 4 to week 5 for several European zones, GMT abbreviation for Sao Paulo, and corrected occurrence for Africa/Cairo and Pacific/Auckland

Comment thread core/ui/src/main/kotlin/org/meshtastic/core/ui/timezone/ZoneIdExtensions.kt Outdated
Comment thread core/ui/src/main/kotlin/org/meshtastic/core/ui/timezone/ZoneIdExtensions.kt Outdated
Comment thread core/ui/src/main/kotlin/org/meshtastic/core/ui/timezone/ZoneIdExtensions.kt Outdated
Comment thread core/ui/src/main/kotlin/org/meshtastic/core/ui/timezone/ZoneIdExtensions.kt Outdated
This commit introduces several enhancements to the POSIX timezone string generation:

- Updates the POSIX string for `America/Sao_Paulo` from the generic "GMT3" to the more specific "BRT3".
- Increases visibility of internal helper functions to `internal` for better testability.
- Adds comprehensive unit tests for `formatAbbreviation` and `formatPosixOffset` to ensure correctness of timezone string components.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
Refine the `toPosixString` extension function for `ZoneId` by addressing an issue where `firstOrNull` could select an incorrect, historical transition rule.

By changing `firstOrNull` to `lastOrNull`, the function now correctly selects the most recent "spring" and "fall" daylight saving transition rules. This ensures a more accurate POSIX timezone string generation for zones with multiple historical rule changes. Additionally, the logic is simplified to check for `isEmpty()` on `transitionRules` instead of `< 2`.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
@codecov

codecov Bot commented Dec 28, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (b3aa2b6) to head (622d221).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #4087   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files          2       2           
  Lines         19      19           
  Branches       7       7           
=====================================
  Misses        19      19           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Replaces `Year.now()` with a constant `REFERENCE_YEAR` (2025) when creating a `ZoneOffsetTransitionRule`. This ensures deterministic generation of the POSIX timezone string, independent of the current date.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
The explicit `java.time.LocalTime` type declaration for `wallTime` is removed, as it can be inferred by the compiler.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

Comment thread core/ui/src/main/kotlin/org/meshtastic/core/ui/timezone/ZoneIdExtensions.kt Outdated
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
@jamesarich jamesarich enabled auto-merge December 28, 2025 20:37
@jamesarich jamesarich added this pull request to the merge queue Dec 28, 2025
Merged via the queue into main with commit 0f00332 Dec 28, 2025
6 checks passed
@jamesarich jamesarich deleted the fix/posix-tz-strings branch December 28, 2025 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix PR tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Time Zone POSIX String generation is wrong

2 participants