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

Fix for YAML spec failure with new nanoseconds precision #5069

Merged

Conversation

straight-shoota
Copy link
Member

This fixes a failing spec which was introduced by merging #5007 and #5022

/cc @asterite @mverzilli

@mverzilli
Copy link

Aaaaand with this change you've unblocked Crystal's 0.24 release 🎉

@mverzilli mverzilli added this to the Next milestone Oct 2, 2017
@RX14
Copy link
Contributor

RX14 commented Oct 2, 2017

I think that the breaking change in the time constructor introduced by #5022 this PR highlights was unneccesary. It's silently broken this in a very subtle way, I think breaking changes should be a lot less subtle and easy to miss than this.

@straight-shoota
Copy link
Member Author

Yes, I was actually surprised that #5022 didn't break much at all.

Copy link
Contributor

@RX14 RX14 left a comment

Choose a reason for hiding this comment

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

I'd rather #5022 was changed. Or at least more discussion of that.

@bew
Copy link
Contributor

bew commented Oct 2, 2017

I think that the breaking change in the time constructor introduced by #5022 this PR highlights was unneccesary. It's silently broken this in a very subtle way, I think breaking changes should be a lot less subtle and easy to miss than this.

I agree, maybe we should leave the constructor with the sane logic it had before, and add (one more?) Time constructor with a named argument to specify even more precision?

@mverzilli
Copy link

I don't think it's a good idea to keep adding constructors just for backwards compatibility pre-1.0, although I agree that the situation is a bit confusing. I think the root cause here is that Time constructors are accepting a lot of unnamed primitive type params. Maybe we should avoid introducing constructors like that into the stdlib in the future.

@akzhan
Copy link
Contributor

akzhan commented Oct 2, 2017

I'm sorry but pull requests broke a lot a things :) Now proposed #5070 to eliminate bugs found.

It's strange for me that #5069 passes the specs :)

@straight-shoota
Copy link
Member Author

In the long run, it makes more sense to have the default argument after seconds be nanoseconds because that's the precision we want. Because currently it's milliseconds, it needs to break at some point.

It might be the right thing to have it break now. It might also be better to wait for upcoming changes to time class and break multiple things at once instead of little steps.

An idea for a smooth transition could be to use the argument as nanosecond but only allow millisecond (or microsecond) precision for now. Until the next release, all values smaller than 1000 could throw an exception to allow identifying millisecond values. Afterwards the limit could be removed to allow full nanosecond precision. If nanosecond precision is needed right away, the new constructor with second and nanosecond named arguments can be used.

Copy link
Contributor

@akzhan akzhan left a comment

Choose a reason for hiding this comment

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

It looks like a part of fix (and specs are test Time values incorrectly, I suppose, subject for another investigation). So please review #5070 instead of this PR.

@@ -305,7 +305,7 @@ describe "YAML serialization" do
end

it "does for utc time with milliseconds" do
time = Time.new(2010, 11, 12, 1, 2, 3, 456, kind: Time::Kind::Utc)
time = Time.new(2010, 11, 12, 1, 2, 3, 456_000_000, kind: Time::Kind::Utc)
Copy link
Contributor

Choose a reason for hiding this comment

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

Formatters and parsers are broken AFAIS, and I have proposed #5070. I don't know why you code pass the specs :)

Copy link
Member

Choose a reason for hiding this comment

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

They are not broken. They just lack precision, but that's expected because at that time Time didn't have that precision... So #5070 is a feature, not a bug fix.

@asterite
Copy link
Member

asterite commented Oct 3, 2017

I'm fine with having different overloads that accept millisecond and nanosecond as required named arguments to avoid confusion. So if someone wants to implement that, go ahead.

@asterite
Copy link
Member

asterite commented Oct 3, 2017

@RX14 I think this can be merged. I think the changes you are requesting are "you should have fixed this in a PR that was already merged", but that's a bit impossible right now.

@mverzilli mverzilli merged commit 25392e1 into crystal-lang:master Oct 3, 2017
@mverzilli
Copy link

Let's start by merging this so we get a passing master again.

@straight-shoota straight-shoota deleted the fix-yaml-spec-nanoseconds branch November 18, 2021 17:43
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.

None yet

6 participants