-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Showing fractional seconds in Time#inspect #2194
Showing fractional seconds in Time#inspect #2194
Conversation
We need to change the behaviour of `#inspect` without affecting `#to_s`.
This creates the opportunity to append the fractional time first.
Although the Ruby specs don’t demonstrate it, we need to strip the trailing zeros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
str.force_encoding Encoding::US_ASCII | ||
end | ||
|
||
def to_s | ||
if gmt? | ||
str = strftime('%Y-%m-%d %H:%M:%S UTC') | ||
else | ||
str = strftime('%Y-%m-%d %H:%M:%S %z') | ||
end | ||
str.force_encoding Encoding::US_ASCII |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems better to refactor to_s
to also use the str << (gmt? ? ' UTC' : strftime(' %z'))
approach to make comparison easier, I'll do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I wasn’t sure of the performance impact of mutating the string so I erred on the side of leaving it alone, but I agree it’s better to make it look the same if there’s no downside.
(I'll fix the lint issue) |
PullRequest: truffleruby/2272
I feel like this got merged - why didn't the bot close it? |
Sorry for the inconvenience, and thanks for sorting it out. I’ll beware of this in future. |
No worry :) |
…2194) PullRequest: truffleruby/2278
Creating on behalf of @tomstuart.
Showing fractional seconds in Time#inspect is Ruby feature #15958, required for Ruby 2.7 compatibility per #2004. This PR satisfies one of the two ruby/spec tests for Time#inspect.
The other spec is probably too MRI specific. We'll address that elsewhere.
Shopify#1