0
我想從時區對象中找到總的UTC偏移量。以下是使用TZInfo::Timezone
和ActiveSupport::TimeZone
的兩個示例。最終,我想使用ActiveSupport::TimeZone
實現,但不能讓它給我正確的答案。Ruby TZInfo和Rails ActiveSupport :: Timezone UTC_offset的差異
#TZInfo implementation
tz = TZInfo::Timezone.get('America/New_York')
tz.current_period.utc_total_offset/60/60
=> -4 (CORRECT)
# Rails implementation
tz = ActiveSupport::TimeZone.new("Eastern Time (US & Canada)")
tz.utc_offset/60/60
=> -5 (WRONG)
爲什麼ActiveSupport::TimeZone
似乎無法考慮dst?我如何解決這個問題?