Skip to content

Load Location.local by symlink name#16002

Merged
straight-shoota merged 1 commit intocrystal-lang:masterfrom
straight-shoota:feat/localtime-by-name
Jul 21, 2025
Merged

Load Location.local by symlink name#16002
straight-shoota merged 1 commit intocrystal-lang:masterfrom
straight-shoota:feat/localtime-by-name

Conversation

@straight-shoota
Copy link
Member

@straight-shoota straight-shoota commented Jul 19, 2025

Previously, Time::Location.local on Unix systems would always have a generic name, Local (or UTC if /etc/localtime is missing) because the zoneinfo described in /etc/localtime does not have an obvious name attached.

/etc/localtime is typically a symlink into the zoneinfo database. With this change, we read the symlink and defer the name of the location from the path inside the zoneinfo root directory. We do not actually parse the target file and instead load the location by name.

Originally suggested in https://forum.crystal-lang.org/t/how-do-you-get-the-location-name-of-the-local-timezone/8191/3?u=straight-shoota, with alterations from #15959 (comment) (same as jiff).

Supersedes #15959. I think this is the better solution because with #15959 we could end up with two location instances with the same name but potentially different rules.

@straight-shoota straight-shoota self-assigned this Jul 19, 2025
@straight-shoota straight-shoota changed the title Load Location.local from symlink name Load Location.local by symlink name Jul 19, 2025
@straight-shoota straight-shoota added this to the 1.18.0 milestone Jul 19, 2025
@straight-shoota straight-shoota merged commit 530bd28 into crystal-lang:master Jul 21, 2025
41 checks passed
@straight-shoota straight-shoota deleted the feat/localtime-by-name branch July 21, 2025 21:34
straight-shoota added a commit that referenced this pull request Jul 23, 2025
…16022)

Fixes a regression caused by simultaneous changes to the same code in #16004 and #16002 (#16004 (comment)).

The call was never supposed to go to `File.readlink` (i.e. `Crystal::System::File.readlink`) but the public method `::File.readlink`.
Now with `::File.readlink?` available from #16004, we can use that directly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants