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

Implement strftime #12

Merged
merged 37 commits into from
Aug 15, 2022
Merged

Implement strftime #12

merged 37 commits into from
Aug 15, 2022

Conversation

x-hgg-x
Copy link
Collaborator

@x-hgg-x x-hgg-x commented Aug 10, 2022

Implement strftime.

@x-hgg-x x-hgg-x marked this pull request as draft August 10, 2022 17:15
Copy link
Member

@lopopolo lopopolo left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @x-hgg-x! I'm excited to see where this goes.

Just to clarify, is your intent to match the behavior of all the time specifiers found in https://github.com/artichoke/strftime-ruby/blob/trunk/vendor/ruby-3.1.2/strftime.c?

src/format.rs Outdated Show resolved Hide resolved
src/format.rs Outdated Show resolved Hide resolved
src/format.rs Outdated Show resolved Hide resolved
src/utils.rs Outdated Show resolved Hide resolved
@lopopolo lopopolo added A-formatter Area: strftime formatting. A-parser Area: strftime parser. S-wip Status: This pull request is a work in progress. labels Aug 10, 2022
@x-hgg-x
Copy link
Collaborator Author

x-hgg-x commented Aug 10, 2022

Yes, I use the specification at https://ruby-doc.org/core-3.1.2/Time.html#method-i-strftime, with verification using the interpreter.

@lopopolo
Copy link
Member

Awesome thank you!

@x-hgg-x
Copy link
Collaborator Author

x-hgg-x commented Aug 11, 2022

Potential inconsistency with Ruby 3.1.2:

Time.new(2021,10,21,1,1,1,'Z').wday # 7 (Sunday)
Time.at(Time.new(2021,10,21,1,1,1,'Z'), in: 'Z').wday # 4 (Thursday)

@x-hgg-x
Copy link
Collaborator Author

x-hgg-x commented Aug 11, 2022

It seems that many specifiers are invalid when the time zone is UTC:

Time.new(2019,12,31,12,1,1,'Z').strftime("%G %g %V %U %W %u %w %j %a %A") # "2019 19 00 00 00 7 6 001 ? ?"
Time.new(2019,12,31,12,1,1,'A').strftime("%G %g %V %U %W %u %w %j %a %A") # "2020 20 01 52 52 2 2 365 Tue Tuesday"

@lopopolo
Copy link
Member

It seems that many specifiers are invalid when the time zone is UTC:

Time.new(2019,12,31,12,1,1,'Z').strftime("%G %g %V %U %W %u %w %j %a %A") # "2019 19 00 00 00 7 6 001 ? ?"
Time.new(2019,12,31,12,1,1,'A').strftime("%G %g %V %U %W %u %w %j %a %A") # "2020 20 01 52 52 2 2 365 Tue Tuesday"

yea something weird is going on there:

[3.1.2] > Time.new(2019,12,31,12,1,1,'Z').asctime
=> "? Dec 31 12:01:01 2019"
[3.1.2] > Time.new(2019,12,31,12,1,1,'A').asctime
=> "Tue Dec 31 12:01:01 2019"

@lopopolo
Copy link
Member

lopopolo commented Aug 11, 2022

Potential inconsistency with Ruby 3.1.2:

Time.new(2021,10,21,1,1,1,'Z').wday # 7 (Sunday)
Time.at(Time.new(2021,10,21,1,1,1,'Z'), in: 'Z').wday # 4 (Thursday)

Adding some more examples of this weirdness:

[3.1.2] > Time.new(2021,10,21,1,1,1,'Z').asctime
=> "? Oct 21 01:01:01 2021"
[3.1.2] > Time.at(Time.new(2021,10,21,1,1,1,'Z'), in: 'Z').asctime
=> "Thu Oct 21 01:01:01 2021"
[3.1.2] > Time.new(2021,10,21,1,1,1, in: 'Z').asctime
=> "? Oct 21 01:01:01 2021"
[3.1.2] > Time.at(Time.new(2021,10,21,1,1,1,in: 'Z'), in: 'Z').asctime
=> "Thu Oct 21 01:01:01 2021"

@lopopolo
Copy link
Member

yea something weird is going on there

I'm taking a guess here but I bet Time::new manually populates the tm struct from time.h whereas Time::at actually does timezone resolution.

Regardless, I think what spinoso-time and tz-rs + tzdb are doing is more correct and I think it's too much complexity to emulate MRI's (broken) behavior.

Copy link
Member

@lopopolo lopopolo left a comment

Choose a reason for hiding this comment

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

this is looking great so far!

src/format.rs Outdated Show resolved Hide resolved
@x-hgg-x
Copy link
Collaborator Author

x-hgg-x commented Aug 11, 2022

The doc of spinoso_time::tzrs::Time::day_of_year() is inconsistent with its implementation:
https://github.com/artichoke/artichoke/blob/b3284a42fb0d175da1a822bda73bd300ddab72c3/spinoso-time/src/time/tzrs/parts.rs#L511-L533.

tz::datetime::DateTime returns a year day in [0, 365], but the spinoso_time doc say it should be in 1..366 (1..=366 is more correct I think).

@lopopolo
Copy link
Member

The doc of spinoso_time::tzrs::Time::day_of_year() is inconsistent with its implementation: https://github.com/artichoke/artichoke/blob/b3284a42fb0d175da1a822bda73bd300ddab72c3/spinoso-time/src/time/tzrs/parts.rs#L511-L533.

tz::datetime::DateTime returns a year day in [0, 365], but the spinoso_time doc say it should be in 1..366 (1..=366 is more correct I think).

Bug and PR to fix this:

@lopopolo
Copy link
Member

Fix is merged in artichoke/artichoke@17e469b.

@x-hgg-x

This comment was marked as resolved.

Copy link
Member

@lopopolo lopopolo left a comment

Choose a reason for hiding this comment

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

Thank you so much for the PR @x-hgg-x.

Sorry for the boatload of comments, but this code is tricky and I want to make sure I grok the implementation.

I'd love to grant you commit rights to this repository if that's something you'd be open to. Let me know what you'd like me to do there.

I'll hold off on any more reviewing until you move the PR out of draft to "ready for review".

Thanks again!

Cargo.toml Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
src/format.rs Outdated Show resolved Hide resolved
src/format.rs Outdated Show resolved Hide resolved
src/format.rs Outdated Show resolved Hide resolved
src/utils.rs Outdated Show resolved Hide resolved
src/utils.rs Outdated Show resolved Hide resolved
src/utils.rs Outdated Show resolved Hide resolved
src/utils.rs Outdated Show resolved Hide resolved
src/week.rs Outdated Show resolved Hide resolved
@lopopolo lopopolo removed the S-wip Status: This pull request is a work in progress. label Aug 14, 2022
Copy link
Member

@lopopolo lopopolo left a comment

Choose a reason for hiding this comment

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

tweaks to get the docs to build without std feature.

src/format/write.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/format/write.rs Show resolved Hide resolved
@x-hgg-x x-hgg-x changed the title WIP: Implement strftime Implement strftime Aug 14, 2022
@lopopolo
Copy link
Member

I can prep the release after the tests pass and this gets merged. ooc, given that a trait is part of the public API, should we release as 1.0.0?

@x-hgg-x
Copy link
Collaborator Author

x-hgg-x commented Aug 14, 2022

I think the API is pretty complete at this point, so this should be ok.

Copy link
Member

@lopopolo lopopolo left a comment

Choose a reason for hiding this comment

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

I have a couple of questions. Apart from the suspicious calculation of size_limit, this looks good to go.

Once all of the conversations are resolved, I'll merge this PR.

Huge thank you @x-hgg-x. This is some amazing work.

src/format/mod.rs Outdated Show resolved Hide resolved
src/format/mod.rs Outdated Show resolved Hide resolved
src/format/utils.rs Outdated Show resolved Hide resolved
src/format/week.rs Outdated Show resolved Hide resolved
src/format/write.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/format/mod.rs Outdated Show resolved Hide resolved
Cargo.toml Show resolved Hide resolved
@lopopolo lopopolo mentioned this pull request Aug 15, 2022
lopopolo added a commit that referenced this pull request Aug 15, 2022
Required for the format arguments capture feature which is used in #12.

Fixes #14.
@lopopolo lopopolo mentioned this pull request Aug 15, 2022
Copy link
Member

@lopopolo lopopolo left a comment

Choose a reason for hiding this comment

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

This looks great. Now that #15 is merged, the MSRV check should pass. Please rebase and then I'll merge.

@lopopolo lopopolo merged commit 8f7ecbf into artichoke:trunk Aug 15, 2022
@lopopolo
Copy link
Member

🎉

@x-hgg-x thank you again so much. I'll make you a maintainer here later today when I'm done with work.

There are a few changes I'd like to try and make, e.g. removing the bitflags dep. I'll tag you as a reviewer.

Hopefully we can push out a 1.0 by the end of this week or next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-formatter Area: strftime formatting. A-parser Area: strftime parser.
Development

Successfully merging this pull request may close these issues.

2 participants