twitter/twitter-cldr-rb

`Date` + `LocalizedDate` doesn't work

sandstrom opened this issue · 3 comments

# doesn't work
ld = TwitterCldr::Localized::LocalizedDate.new(Date.today, 'sv')
ld.to_medium_s #=> NoMethodError: undefined method `utc' for nil:NilClass

# works
ld = TwitterCldr::Localized::LocalizedDate.new(Date.today.to_time, 'sv')
ld.to_medium_s #=> "29 dec. 2015"

This line throws the exception:
https://github.com/twitter/twitter-cldr-rb/blob/master/lib/twitter_cldr/localized/localized_date.rb#L46

Possible cause is that this switch doesn't handle Date. The temporal classes in ruby has always been confusing, there is Date, DateTime and Time. Moreover DateTime.new.is_a?(Date) #=> true.

A workaround is easy (I'll simply cast to Time first), but thought I'd let you know about this.

Thanks for a great library! ⛵

Hey @sandstrom thanks for the bug report. My memory is that I removed Date support on purpose back when the library still supported Ruby 1.8 and the to_time and to_date methods didn't exist. Looks like it got added back in, but with a bug. Honestly the "temporal" classes as you call them are confusing and irritating to work with. Should be straightforward to fix however. Are you interested in submitting a pull request?

I'm sorry but I don't have time right now, too much regular work. Feel free to close this, or leave it open for a while to see if someone else has the same issue.

Since there is a super-simple work-around available (at least to me) it isn't much of an issue.

This has been fixed in v4.0.0.