Skip to content

Add Time::Location.load?#16121

Merged
straight-shoota merged 1 commit intocrystal-lang:masterfrom
straight-shoota:feat/time_location-load
Sep 5, 2025
Merged

Add Time::Location.load?#16121
straight-shoota merged 1 commit intocrystal-lang:masterfrom
straight-shoota:feat/time_location-load

Conversation

@straight-shoota
Copy link
Member

This is a convenience method that returns nil if a location name doesn't exist.
This makes it possible to implement a fallback without a raise/rescue trip: Time::Location.load?("Asia/Jerusalem") || Time::Location.load?("Asia/Tel_Aviv").

# Raises `InvalidTZDataError` if the loader encounters a format error in the
# time zone database.
#
# - `.load` raises if the location is unavailable.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's weird to get a bullet point about the behavior of another, alternative method, without any introduction to why we talk about it. For example "Consider X instead to raise when the location is unavailable" (same remark for .load).

Copy link
Member Author

Choose a reason for hiding this comment

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

We use the same format in many other doc comments. I suppose we could introduce the list with "See also:"? But it feels odd to do this only a single instance. We should update the existing documentation as well, which makes it a different change.

Copy link
Contributor

Choose a reason for hiding this comment

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

The :ditto: includes the entire doc comment for .load, by the way

Copy link
Member Author

Choose a reason for hiding this comment

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

I know. It seems bad to duplicate the entire documentation, either. 😢

@straight-shoota straight-shoota added this to the 1.18.0 milestone Sep 3, 2025
@straight-shoota straight-shoota merged commit 0983e8d into crystal-lang:master Sep 5, 2025
41 checks passed
@straight-shoota straight-shoota deleted the feat/time_location-load branch September 5, 2025 08:53
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.

4 participants