Skip to content

Add Time.month_week_date#15620

Merged
straight-shoota merged 2 commits intocrystal-lang:masterfrom
HertzDevil:feature/time-month-week-date
Apr 24, 2025
Merged

Add Time.month_week_date#15620
straight-shoota merged 2 commits intocrystal-lang:masterfrom
HertzDevil:feature/time-month-week-date

Conversation

@HertzDevil
Copy link
Contributor

This function returns a Time instance using a given month, week of month, and day of week. It is similar to the existing .week_date, except the week number is relative to the given month, not the beginning of the given year (or the end of the previous year).

Windows time zone transitions are specified in this manner, as are the M dates of POSIX TZ strings.

# * `year`: `1..9999`
# * `month`: `1..12`
# * `week`: `1..5`
# * `day_of_week`: `0..7`
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be either 1..7 or 0..6 (or 0...7)

Copy link
Member

Choose a reason for hiding this comment

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

This is congruent with DayOfWeek.from_value which accepts either 0 or 7 for Sunday.

Copy link
Member

Choose a reason for hiding this comment

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

In fact, I think there could be some value in using DayOfWeek.from_value here. It implicitly handles domain errors.
Perhaps the parameter restriction should even be narrowed to DayOfWeek, instead of the union?
An enum value is more explicit than a plain number.

I realize that .week_date has union type restriction as well, so that would be a change.

@straight-shoota straight-shoota added this to the 1.17.0 milestone Apr 22, 2025
@straight-shoota straight-shoota merged commit 74f6213 into crystal-lang:master Apr 24, 2025
38 of 39 checks passed
@HertzDevil HertzDevil deleted the feature/time-month-week-date branch May 6, 2025 05:26
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