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

TZInfo::PeriodNotFound - is an invalid local time #110

Closed
paduszynski opened this issue Dec 12, 2019 · 2 comments
Closed

TZInfo::PeriodNotFound - is an invalid local time #110

paduszynski opened this issue Dec 12, 2019 · 2 comments
Labels

Comments

@paduszynski
Copy link

@paduszynski paduszynski commented Dec 12, 2019

We spotted error with one specific time

tz = TZInfo::Timezone.get('Europe/Madrid')
time = Time.parse('2020-03-29T02:30:00Z')
tz.local_to_utc(time)

This leads to error {TZInfo::PeriodNotFound} 2020-03-29 02:30:00 is an invalid local time.

.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/tzinfo-2.0.0/lib/tzinfo/timezone.rb:500:in period_for_local' .rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/tzinfo-2.0.0/lib/tzinfo/timezone.rb:652:in block in local_to_utc'
.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/tzinfo-2.0.0/lib/tzinfo/timestamp.rb:142:in for' .rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/tzinfo-2.0.0/lib/tzinfo/timezone.rb:648:in local_to_utc'

changing it to any other hour or day seems to work fine

here Ruby 2.5.5 (but is the same for 2.5.7)

tzinfo (2.0.0)
  concurrent-ruby (~> 1.0)
tzinfo-data (1.2019.3)
  tzinfo (>= 1.0.0)
@paduszynski
Copy link
Author

@paduszynski paduszynski commented Dec 12, 2019

and simple rspec

it 'test failing local_to_utc' do
  tz = TZInfo::Timezone.get('Europe/Warsaw')
  time = Time.parse('2019-01-01T02:30:00Z')
  failed = []

  10000.times do |day|
    24.times do |hour|
      new_time = time + day * 60 * 60 * 24 + hour * 60 * 60
      tz.local_to_utc(new_time)
    rescue => _
      failed << new_time.iso8601
    end
  end

  expect(failed).to be_empty
end

this returns
"2019-03-31T02:30:00Z", "2019-10-27T02:30:00Z", "2020-03-29T02:30:00Z", "2020-10-25T02:30:00Z", "2021-03-28T02:30:00Z", "2021-10-31T02:30:00Z", "2022-03-27T02:30:00Z", "2022-10-30T02:30:00Z", "2023-03-26T02:30:00Z", "2023-10-29T02:30:00Z", "2024-03-31T02:30:00Z", "2024-10-27T02:30:00Z", "2025-03-30T02:30:00Z", "2025-10-26T02:30:00Z", "2026-03-29T02:30:00Z", "2026-10-25T02:30:00Z", "2027-03-28T02:30:00Z", "2027-10-31T02:30:00Z", "2028-03-26T02:30:00Z", "2028-10-29T02:30:00Z", "2029-03-25T02:30:00Z", "2029-10-28T02:30:00Z", "2030-03-31T02:30:00Z", "2030-10-27T02:30:00Z", "2031-03-30T02:30:00Z", "2031-10-26T02:30:00Z", "2032-03-28T02:30:00Z", "2032-10-31T02:30:00Z", "2033-03-27T02:30:00Z", "2033-10-30T02:30:00Z", "2034-03-26T02:30:00Z", "2034-10-29T02:30:00Z", "2035-03-25T02:30:00Z", "2035-10-28T02:30:00Z", "2036-03-30T02:30:00Z", "2036-10-26T02:30:00Z", "2037-03-29T02:30:00Z", "2037-10-25T02:30:00Z", "2038-03-28T02:30:00Z", "2038-10-31T02:30:00Z", "2039-03-27T02:30:00Z", "2039-10-30T02:30:00Z", "2040-03-25T02:30:00Z", "2040-10-28T02:30:00Z", "2041-03-31T02:30:00Z", "2041-10-27T02:30:00Z", "2042-03-30T02:30:00Z", "2042-10-26T02:30:00Z", "2043-03-29T02:30:00Z", "2043-10-25T02:30:00Z", "2044-03-27T02:30:00Z", "2044-10-30T02:30:00Z", "2045-03-26T02:30:00Z", "2045-10-29T02:30:00Z", "2046-03-25T02:30:00Z"

@paduszynski
Copy link
Author

@paduszynski paduszynski commented Dec 12, 2019

Ok false alarm, there is no such hour because we change time from 2:00 to 3:00, everything is as it should

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants