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

Support Time.new with string timestamp argument and error when invalid #3702

Merged
merged 7 commits into from
Nov 6, 2024

Conversation

rwstauner
Copy link
Collaborator

closes #3693

Use a regexp to quickly detect if a timestamp string is valid.
If it isn't raise an ArgumentError for consistency with CRuby 3.2+.

I added a few new specs for behavior I noticed that I didn't see in the existing specs.
It's not that difficult to match the existing error messages, but I'm not sure how valuable they are.

Here are some examples of the differences:

Expected ArgumentError (missing sec part: 00:56 )
but got: ArgumentError (can't parse: "2020-12-25 00:56 +09:00")

Expected ArgumentError (subsecond expected after dot: 00:56:17. )
but got: ArgumentError (can't parse: "2020-12-25 00:56:17. +0900")

Expected ArgumentError (year must be 4 or more digits: 021)
but got: ArgumentError (can't parse: "021-12-25 00:00:00.123456 +09:00")

Expected ArgumentError (mon out of range)
but got: ArgumentError (can't parse: "2020-13-25 00:56:17 +09:00")

As discussed, this relaxes the error message specs to keep the code simple.

This removes the "fails" tags for the "Time.new with a String argument" specs except for the three precision related ones which TruffleRuby isn't doing anything with yet.

Copy link

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. label Nov 1, 2024
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.

Thank you, it look great and simple.
I left some comments to improve it further.

CHANGELOG.md Outdated Show resolved Hide resolved
src/main/ruby/truffleruby/core/truffle/time_operations.rb Outdated Show resolved Hide resolved
src/main/ruby/truffleruby/core/truffle/time_operations.rb Outdated Show resolved Hide resolved
@rwstauner rwstauner force-pushed the time-new-string branch 2 times, most recently from 9b52a02 to 4023a25 Compare November 4, 2024 21:32
Copy link

Thank you for signing the OCA.

@oracle-contributor-agreement oracle-contributor-agreement bot added OCA Verified All contributors have signed the Oracle Contributor Agreement. and removed OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. labels Nov 4, 2024
Comment on lines +99 to +108
if /\A (?<year>\d{4,5})
(?:
- (?<month>\d{2})
- (?<mday> \d{2})
[ T] (?<hour> \d{2})
: (?<min> \d{2})
: (?<sec> \d{2})
(?:\. (?<usec> \d+) )?
\s* (?<offset>\S+)?
)?\z/x =~ str
Copy link
Member

Choose a reason for hiding this comment

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

Beautiful :)

CHANGELOG.md Outdated Show resolved Hide resolved
@eregon eregon added the in-ci The PR is being tested in CI. Do not push new commits. label Nov 5, 2024
@graalvmbot graalvmbot merged commit 3cfc5c9 into oracle:master Nov 6, 2024
14 checks passed
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 Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Compatibility] Time.new should parse a string and error for missing time info
3 participants