TZInfo::PeriodNotFound XYZ 是无效的本地时间
TZInfo::PeriodNotFound XYZ is an invalid local time
我有一个名为 convert_time_with_zone
的方法,它在过去几个月中被调用了数十万次,甚至数百万次。然而今天突然报错
这是我的方法:
def convert_time_with_zone(time)
ActiveSupport::TimeZone.new(time_zone).local_to_utc(time)
end
这是我遇到的错误:
[6] pry(#<Assessment>)> current_day
=> 2022-03-06 02:00:00 +0000
[7] pry(#<Assessment>)> future_day
=> 2022-03-13 02:00:00 +0000
[8] pry(#<Assessment>)> convert_time_with_zone(current_day)
=> 2022-03-06 07:00:00 UTC
[9] pry(#<Assessment>)> convert_time_with_zone(future_day)
TZInfo::PeriodNotFound: 2022-03-13 02:00:00 is an invalid local time.
from /usr/local/bundle/gems/tzinfo-2.0.4/lib/tzinfo/timezone.rb:500:in `period_for_local'
Caused by TZInfo::PeriodNotFound: 2022-03-13 02:00:00 is an invalid local time.
from /usr/local/bundle/gems/tzinfo-2.0.4/lib/tzinfo/timezone.rb:500:in `period_for_local'
[10] pry(#<Assessment>)>
我不明白为什么与工作格式完全相同的另一个格式不起作用。两者之间的唯一区别是一个是3月6日,另一个是3月13日。
那里没有 2022-03-13 02:00,大概是美国时区。
那是美国夏令时“大跃进”的时候。那天本地时钟从 01:59:59 变为 03:00:00。
同样,2022-11-06 01:00 将发生两次,因为时钟“回落”使得在该范围内转换本地时间不明确。
我有一个名为 convert_time_with_zone
的方法,它在过去几个月中被调用了数十万次,甚至数百万次。然而今天突然报错
这是我的方法:
def convert_time_with_zone(time)
ActiveSupport::TimeZone.new(time_zone).local_to_utc(time)
end
这是我遇到的错误:
[6] pry(#<Assessment>)> current_day
=> 2022-03-06 02:00:00 +0000
[7] pry(#<Assessment>)> future_day
=> 2022-03-13 02:00:00 +0000
[8] pry(#<Assessment>)> convert_time_with_zone(current_day)
=> 2022-03-06 07:00:00 UTC
[9] pry(#<Assessment>)> convert_time_with_zone(future_day)
TZInfo::PeriodNotFound: 2022-03-13 02:00:00 is an invalid local time.
from /usr/local/bundle/gems/tzinfo-2.0.4/lib/tzinfo/timezone.rb:500:in `period_for_local'
Caused by TZInfo::PeriodNotFound: 2022-03-13 02:00:00 is an invalid local time.
from /usr/local/bundle/gems/tzinfo-2.0.4/lib/tzinfo/timezone.rb:500:in `period_for_local'
[10] pry(#<Assessment>)>
我不明白为什么与工作格式完全相同的另一个格式不起作用。两者之间的唯一区别是一个是3月6日,另一个是3月13日。
那里没有 2022-03-13 02:00,大概是美国时区。
那是美国夏令时“大跃进”的时候。那天本地时钟从 01:59:59 变为 03:00:00。
同样,2022-11-06 01:00 将发生两次,因为时钟“回落”使得在该范围内转换本地时间不明确。