Add support for meridian indicators on Date
objects
#640
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What are you trying to accomplish?
Fixes #639
What approach did you choose and why?
Assume that the
hour
of aDate
is always0
. Reading the source forDate
, it seems thathour
is set to0
and cannot be changed, regardless of how you create theDate
.My higher-level attempts also failed to set it to anything (adding confidence that I didn't misread the source. For example:
localize
is only meant forDate
,DateTime
, andTime
objects anyway, so I'm not concerned. Besides, if one were to pass in a different object intolocalize
that didn't respond tohour
, then defaulting to 0 would be consistent with the values used in other date libraries. 🤷What should reviewers focus on?
Is there a better way to do this?
Another way to do this would be to bypass the private method safety for
Date
objects by usingsend
:Technically this would run the risk of Ruby changing the private implementation of
Date#hour
, but that feels like it could be an acceptable risk to me?I mostly chose the 0 defaulting way since it felt cleaner and didn't rely on
send
, but I have no strong preferences either way. I'm happy to change it if people feel strongly otherwise.The impact of these changes
Formats with Meridian indicators will once again work with
Date
objects.