Skip to content
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

Merged
merged 4 commits into from
Dec 21, 2020

Conversation

chrisseaton
Copy link
Collaborator

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

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.
@chrisseaton chrisseaton changed the title Upstream fractional seconds Showing fractional seconds in Time#inspect Dec 17, 2020
Copy link
Member

@eregon eregon left a 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
Copy link
Member

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.

Copy link
Contributor

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.

@eregon eregon added the in-ci The PR is being tested in CI. Do not push new commits. label Dec 18, 2020
@eregon
Copy link
Member

eregon commented Dec 18, 2020

(I'll fix the lint issue)

@eregon eregon self-assigned this Dec 18, 2020
graalvmbot pushed a commit that referenced this pull request Dec 18, 2020
PullRequest: truffleruby/2272
@chrisseaton
Copy link
Collaborator Author

I feel like this got merged - why didn't the bot close it?

@eregon
Copy link
Member

eregon commented Dec 19, 2020

512cd0a is merged.
But 191fe85 was added after the PR was already labeled in-ci and therefore in CI and scheduled for merge.
Please don't add commits after I label with in-ci to avoid this issue.

I'll make a new internal PR with that changelog commit, then it should be marked as merged.

@tomstuart
Copy link
Contributor

Sorry for the inconvenience, and thanks for sorting it out. I’ll beware of this in future.

@eregon
Copy link
Member

eregon commented Dec 19, 2020

No worry :)

graalvmbot pushed a commit that referenced this pull request Dec 21, 2020
@graalvmbot graalvmbot merged commit 191fe85 into oracle:master Dec 21, 2020
@tomstuart tomstuart deleted the upstream-fractional-seconds branch January 5, 2021 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in-ci The PR is being tested in CI. Do not push new commits. oca-signed shopify
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants