Skip to content

Add ExtendedClientDetails.getZoneId() #26034

Description

@mvysny

Describe your motivation

To show dates and times in the user's time zone, you need a java.time.ZoneId. ExtendedClientDetails offers the pieces, getTimeZoneId() (may be null) and getTimezoneOffset(), but not the ZoneId itself, so every app writes the same conversion. The getBrowserTime() javadoc even spells it out:

String timeZoneId = details.getTimeZoneId();
ZoneId zone = timeZoneId != null ? ZoneId.of(timeZoneId)
        : ZoneId.systemDefault();

The fallback there is the server's time zone, which is usually wrong for the user. The browser has already reported its offset, which is a far better fallback.

Describe the solution you'd like

public ZoneId getZoneId()

It returns ZoneId.of(getTimeZoneId()) when the browser reported a zone ID; otherwise the ZoneOffset from getTimezoneOffset(). Never null. The zone ID is preferred over the offset since only the ID gets daylight saving right for other dates than today.

Things worth deciding in the PR: whether to fall back to the offset also when ZoneId.of() rejects an ID the JVM doesn't know, and whether the getBrowserTime() javadoc should then use getZoneId().

Describe alternatives you've considered

The conversion above, written in the app.

Additional context

No response

Activity

  1. totally-not-ai commented on Sep 29, 2026

    @totally-not-ai
    Contributor

    This is a valid request. ExtendedClientDetails already has everything needed: getTimeZoneId() (nullable) and getTimezoneOffset(). The getBrowserTime() javadoc currently suggests ZoneId.systemDefault() as the fallback, but that is the server's zone, which is usually the wrong one for the user.

    Proposed solution (implemented in a draft PR that links this issue):

    public ZoneId getZoneId()
    • Returns ZoneId.of(getTimeZoneId()) when the browser reported an ID. This is preferred because only a region-based zone gets DST right for dates other than today.
    • Otherwise returns ZoneOffset.ofTotalSeconds(getTimezoneOffset() / 1000). This offset already includes DST that is in effect right now.
    • Never returns null.

    On the open questions:

    • Should an ID the JVM doesn't know fall back to the offset? Yes. ZoneId.of throws DateTimeException (e.g. an old JDK tzdb meeting a newly renamed zone, or a garbage value from the client). Throwing from a getter over client-supplied data would be a trap, and the offset is still correct for "now". An out-of-range offset (only possible with a tampered payload) falls back to UTC, which matches the existing "0 if not available" contract of getTimezoneOffset().
    • Should the getBrowserTime() javadoc use it? Yes. The example becomes details.getBrowserTime().atZone(details.getZoneId()).
  2. mvysny commented on Sep 29, 2026

    @mvysny
    MemberAuthor

    I agree with both of your suggestions in the open questions. Totally-not-ai, please implement and create a PR.

  3. mvysny commented on Sep 29, 2026

    @mvysny
    MemberAuthor

    Eh, totally-not-ai is not listening, so I enlisted my own totally-not-ai :-D

  4. added a commit that references this issue on Oct 1, 2026
    f898517
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions