truffleruby icon indicating copy to clipboard operation
truffleruby copied to clipboard

Time.new and Time#getlocal don't accept a timezone object or a UTC offset string

Open deepj opened this issue 6 years ago • 5 comments

This a new thing in Ruby 2.6. I personally use this in one script loading some Timezones from various coordinates.

To reproduce:

ruby -e 'require "tzinfo"; puts Time.new(2019, 5, 8, 2, 34, 23, TZInfo::Timezone.get("Europe/Zurich"))'

MR 2.6.3:

2019-05-08 02:34:23 +0200

TruffleRuby 19.1.0

-e:1:in `coerce_to_failed': Coercion error: #<TZInfo::DataTimezone: Europe/Zurich>.to_int => Integer failed (TypeError)
	from -e:1:in `execute_coerce_to'
	from -e:1:in `coerce_to'
	from -e:1:in `coerce_to_exact_num'
	from -e:1:in `coerce_to_utc_offset'
	from -e:1:in `new'
	from -e:1:in `<main>'

deepj avatar Jul 07 '19 21:07 deepj

Now the error is a bit different:

<internal:core> core/type.rb:104:in `coerce_to_failed': wrong argument type TZInfo::DataTimezone (expected Integer) (TypeError)
	from <internal:core> core/type.rb:93:in `execute_coerce_to'
	from <internal:core> core/type.rb:85:in `coerce_to'
	from <internal:core> core/type.rb:457:in `coerce_to_exact_num'
	from <internal:core> core/type.rb:472:in `coerce_to_utc_offset'
	from <internal:core> core/time.rb:459:in `new'
	from -e:1:in `<main>'
<internal:core> core/type.rb:91:in `execute_coerce_to': undefined method `to_int' for #<TZInfo::DataTimezone: Europe/Zurich> (NoMethodError)
Did you mean?  taint
	from <internal:core> core/type.rb:85:in `coerce_to'
	from <internal:core> core/type.rb:457:in `coerce_to_exact_num'
	from <internal:core> core/type.rb:472:in `coerce_to_utc_offset'
	from <internal:core> core/time.rb:459:in `new'
	from -e:1:in `<main>'

No issue with MRI rubies thought

deepj avatar Jun 24 '22 12:06 deepj

Thank you for reporting!

It can be reproduced easily. Will work on a fix.

andrykonchin avatar Nov 14 '22 17:11 andrykonchin

I traced this back to Feature 14850 with this commit https://github.com/ruby/ruby/commit/ee58c638b8d10d2ea10faadbc7b34515d2f2e351

The 3.3 docs have more info on how it works: https://docs.ruby-lang.org/en/3.3/Time.html#class-Time-label-Timezone+Objects

rwstauner avatar Feb 08 '24 15:02 rwstauner

@andrykonchin Did you do any work towards this? Do you mind if I work on a PR for it?

rwstauner avatar Feb 08 '24 15:02 rwstauner

No, timezone object isn't supported yet. It will be great to have it implemented!

It should be already covered with specs AFAIK (for #getlocal and .new methods)

andrykonchin avatar Feb 08 '24 17:02 andrykonchin