Fix Time.new parsing (time/new_tags.txt)#8890
Conversation
The idea was to help towards this jruby#8736 but most of the fixes here are specifically around parsing the time string, not timezone related. @enebo I noticed you did recent changes around Time.new parsing as well, in case you want to review. I'll add some comments in the PR to highlight which changes fix which parts, but here is the TLDR: - Time.new parsing should ignore "whitespace" chars, not only space chars - precision keyword argument should only be used by Time.new parsing and ignored otherwise (see Ruby docs), and it should default to 9 - RubyTimeParser.parseInt now returns nil if no digits (so missing year can be detected) and only to a set number of digits (for subsec precision) - correctly convert subsec to microseconds in RubyTimeParser when more than 9 digits
| fails(not implemented, jruby/jruby#6161):Time.new with a timezone argument subject's class implements .find_timezone method calls .find_timezone to build a time object at loading marshaled data | ||
| fails(only during full spec run):Time.new with a utc_offset argument raises ArgumentError if the String argument is not of the form (+|-)HH:MM | ||
| fails:Time.new with a timezone argument returned value by #utc_to_local and #local_to_utc methods cannot have arbitrary #utc_offset if it is an instance of Time | ||
| fails(https://github.com/jruby/jruby/issues/8736):Time.new with a timezone argument :in keyword argument allows omitting minor arguments |
There was a problem hiding this comment.
This was already passing, I think I might have fixed it in my previous PR: #8858
But I wasn't aware of these tag files.
| fails:Time.new with a timezone argument returned value by #utc_to_local and #local_to_utc methods cannot have arbitrary #utc_offset if it is an instance of Time | ||
| fails(https://github.com/jruby/jruby/issues/8736):Time.new with a timezone argument :in keyword argument allows omitting minor arguments | ||
| fails(https://github.com/jruby/jruby/issues/8736):Time.new with a timezone argument Time.new with a String argument accepts precision keyword argument and truncates specified digits of sub-second part | ||
| fails(https://github.com/jruby/jruby/issues/8736):Time.new with a timezone argument Time.new with a String argument converts precision keyword argument into Integer if is not nil |
There was a problem hiding this comment.
Removing the type error in RubyTime basically fixed this. We already call toLong in the RubyTimeParser.
I also noticed that the precision keyword argument is only supposed to be used when parsing a ruby time string and ignore otherwise, and it should default to 9.
| fails(only during full spec run):Time.new with a utc_offset argument raises ArgumentError if the String argument is not of the form (+|-)HH:MM | ||
| fails:Time.new with a timezone argument returned value by #utc_to_local and #local_to_utc methods cannot have arbitrary #utc_offset if it is an instance of Time | ||
| fails(https://github.com/jruby/jruby/issues/8736):Time.new with a timezone argument :in keyword argument allows omitting minor arguments | ||
| fails(https://github.com/jruby/jruby/issues/8736):Time.new with a timezone argument Time.new with a String argument accepts precision keyword argument and truncates specified digits of sub-second part |
There was a problem hiding this comment.
RubyTime only has precision up to 9 (nanoseconds) so it is not possible to remove this tag, but the microseconds conversion was wrong ( + 3 vs - 3) when there were more than 9 digits. So it now truncates correctly.
| fails(https://github.com/jruby/jruby/issues/8736):Time.new with a timezone argument Time.new with a String argument converts precision keyword argument into Integer if is not nil | ||
| fails(https://github.com/jruby/jruby/issues/8736):Time.new with a timezone argument Time.new with a String argument raises ArgumentError if date/time parts values are not valid | ||
| fails(https://github.com/jruby/jruby/issues/8736):Time.new with a timezone argument Time.new with a String argument raises ArgumentError if utc offset parts are not valid | ||
| fails(https://github.com/jruby/jruby/issues/8736):Time.new with a timezone argument Time.new with a String argument raises ArgumentError if string doesn't start with year |
There was a problem hiding this comment.
Changed the RubyTimeParser.parseInt to return nil if no digits, so we can raise the correct error. Also, this error needs to have the str.inspect() in the error message instead of the plain string.
| fails(https://github.com/jruby/jruby/issues/8736):Time.new with a timezone argument Time.new with a String argument raises ArgumentError when there are leading space characters | ||
| fails(https://github.com/jruby/jruby/issues/8736):Time.new with a timezone argument Time.new with a String argument raises ArgumentError when there are trailing whitespaces |
There was a problem hiding this comment.
These two were just about ignoring more "whitespace" chars, not just spaces.
| fails(https://github.com/jruby/jruby/issues/8736):Time.new with a timezone argument Time.new with a String argument raises ArgumentError if string doesn't start with year | ||
| fails(https://github.com/jruby/jruby/issues/8736):Time.new with a timezone argument Time.new with a String argument raises ArgumentError when there are leading space characters | ||
| fails(https://github.com/jruby/jruby/issues/8736):Time.new with a timezone argument Time.new with a String argument raises ArgumentError when there are trailing whitespaces | ||
| fails:Time.new with a timezone argument Time.new with a String argument returns Time with correct subseconds when given seconds fraction is longer than 9 digits |
There was a problem hiding this comment.
This was fixed by adding support for "precision" in RubyTimeParser.parseInt.
| fails:Time.new with a utc_offset argument returns a Time with a UTC offset of the specified number of Rational seconds | ||
| fails:Time.new with a utc_offset argument raises ArgumentError if the String argument is not in an ASCII-compatible encoding | ||
| fails:Time.new with a utc_offset argument with an argument that responds to #to_r coerces using #to_r | ||
| fails:Time.new with a utc_offset argument raises ArgumentError if the month is greater than 12 |
There was a problem hiding this comment.
This was already passing, so I just removed it.
|
@PChambino cool. The -3 vs +3 makes sense and explains a confusion I had when working on the other recent PR I did 😄. I am mildly confused about the already passing specs since I thought I had did a mspec-tag to untag passing things but I must have done that manually? |
The idea was to help towards this #8736 but most of the fixes here are specifically around parsing the time string, not timezone related.
@enebo I noticed you did recent changes around Time.new parsing as well, in case you want to review.
I'll add some comments in the PR to highlight which changes fix which parts, but here is the TLDR:
Time.new parsing should ignore "whitespace" chars, not only space chars
precision keyword argument should only be used by Time.new parsing and ignored otherwise (see Ruby docs), and it should default to 9
RubyTimeParser.parseInt now returns nil if no digits (so missing year can be detected) and only to a set number of digits (for subsec precision)
correctly convert subsec to microseconds in RubyTimeParser when more than 9 digits