Methods
- T
-
- test_all_sorted,
- test_at,
- test_at_with_old_date,
- test_country_zones,
- test_formatted_offset_negative,
- test_formatted_offset_positive,
- test_formatted_offset_zero,
- test_from_duration_to_map,
- test_from_integer_to_map,
- test_index,
- test_local,
- test_local_enforces_fall_dst_rules,
- test_local_enforces_spring_dst_rules,
- test_local_to_utc,
- test_local_with_old_date,
- test_new,
- test_now,
- test_now_enforces_fall_dst_rules,
- test_now_enforces_spring_dst_rules,
- test_parse,
- test_parse_doesnt_use_local_dst,
- test_parse_far_future_date_with_time_zone_offset_in_string,
- test_parse_handles_dst_jump,
- test_parse_returns_nil_when_string_without_date_information_is_passed_in,
- test_parse_should_black_out_app_timezone_dst_jump,
- test_parse_should_not_black_out_system_timezone_dst_jump,
- test_parse_string_with_timezone,
- test_parse_with_day_omitted,
- test_parse_with_incomplete_date,
- test_parse_with_javascript_date,
- test_parse_with_missing_time_components,
- test_parse_with_old_date,
- test_period_for_local,
- test_seconds_to_utc_offset_with_colon,
- test_seconds_to_utc_offset_with_negative_offset,
- test_seconds_to_utc_offset_without_colon,
- test_strptime,
- test_strptime_with_almost_explicit_time_zone,
- test_strptime_with_day_omitted,
- test_strptime_with_explicit_time_zone_as_abbrev,
- test_strptime_with_explicit_time_zone_as_h_offset,
- test_strptime_with_explicit_time_zone_as_hm_offset,
- test_strptime_with_explicit_time_zone_as_hms_offset,
- test_strptime_with_nondefault_time_zone,
- test_to_s,
- test_to_yaml,
- test_today,
- test_tomorrow,
- test_travel_to_a_date,
- test_travel_to_travels_back_and_reraises_if_the_block_raises,
- test_unknown_timezones_delegation_to_tzinfo,
- test_unknown_zone_raises_exception,
- test_unknown_zones_dont_store_mapping_keys,
- test_us_zones,
- test_utc_offset_is_not_cached_when_current_period_gets_stale,
- test_utc_offset_lazy_loaded_from_tzinfo_when_not_passed_in_to_initialize,
- test_utc_to_local,
- test_yaml_load,
- test_yesterday,
- test_z_format_strings,
- test_zone_compare,
- test_zone_match
Included Modules
Instance Public methods
test_all_sorted()
Link
test_at()
Link
# File activesupport/test/time_zone_test.rb, line 199 def test_at zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] secs = 946684800.0 twz = zone.at(secs) assert_equal Time.utc(1999,12,31,19), twz.time assert_equal Time.utc(2000), twz.utc assert_equal zone, twz.time_zone assert_equal secs, twz.to_f end
test_at_with_old_date()
Link
# File activesupport/test/time_zone_test.rb, line 209 def test_at_with_old_date zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] secs = DateTime.civil(1850).to_f twz = zone.at(secs) assert_equal [1850, 1, 1, 0], [twz.utc.year, twz.utc.mon, twz.utc.day, twz.utc.hour] assert_equal zone, twz.time_zone assert_equal secs, twz.to_f end
test_country_zones()
Link
# File activesupport/test/time_zone_test.rb, line 505 def test_country_zones assert ActiveSupport::TimeZone.country_zones("ru").include?(ActiveSupport::TimeZone["Moscow"]) assert !ActiveSupport::TimeZone.country_zones(:ru).include?(ActiveSupport::TimeZone["Kuala Lumpur"]) end
test_formatted_offset_negative()
Link
test_formatted_offset_positive()
Link
test_formatted_offset_zero()
Link
test_from_duration_to_map()
Link
test_from_integer_to_map()
Link
test_index()
Link
# File activesupport/test/time_zone_test.rb, line 479 def test_index assert_nil ActiveSupport::TimeZone["bogus"] assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone["Central Time (US & Canada)"] assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone[8] assert_raise(ArgumentError) { ActiveSupport::TimeZone[false] } end
test_local()
Link
test_local_enforces_fall_dst_rules()
Link
# File activesupport/test/time_zone_test.rb, line 188 def test_local_enforces_fall_dst_rules # 1AM during fall DST transition is ambiguous, it could be either DST or non-DST 1AM # Mirroring Time.local behavior, this method selects the DST time zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] twz = zone.local(2006,10,29,1) assert_equal Time.utc(2006,10,29,1), twz.time assert_equal Time.utc(2006,10,29,5), twz.utc assert_equal true, twz.dst? assert_equal 'EDT', twz.zone end
test_local_enforces_spring_dst_rules()
Link
# File activesupport/test/time_zone_test.rb, line 169 def test_local_enforces_spring_dst_rules zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] twz = zone.local(2006,4,2,1,59,59) # 1 second before DST start assert_equal Time.utc(2006,4,2,1,59,59), twz.time assert_equal Time.utc(2006,4,2,6,59,59), twz.utc assert_equal false, twz.dst? assert_equal 'EST', twz.zone twz2 = zone.local(2006,4,2,2) # 2AM does not exist because at 2AM, time springs forward to 3AM assert_equal Time.utc(2006,4,2,3), twz2.time # twz is created for 3AM assert_equal Time.utc(2006,4,2,7), twz2.utc assert_equal true, twz2.dst? assert_equal 'EDT', twz2.zone twz3 = zone.local(2006,4,2,2,30) # 2:30AM does not exist because at 2AM, time springs forward to 3AM assert_equal Time.utc(2006,4,2,3,30), twz3.time # twz is created for 3:30AM assert_equal Time.utc(2006,4,2,7,30), twz3.utc assert_equal true, twz3.dst? assert_equal 'EDT', twz3.zone end
test_local_to_utc()
Link
# File activesupport/test/time_zone_test.rb, line 15 def test_local_to_utc zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] assert_equal Time.utc(2000, 1, 1, 5), zone.local_to_utc(Time.utc(2000, 1)) # standard offset -0500 assert_equal Time.utc(2000, 7, 1, 4), zone.local_to_utc(Time.utc(2000, 7)) # dst offset -0400 end
test_local_with_old_date()
Link
test_new()
Link
test_now()
Link
# File activesupport/test/time_zone_test.rb, line 53 def test_now with_env_tz 'US/Eastern' do zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'].dup def zone.time_now; Time.local(2000); end assert_instance_of ActiveSupport::TimeWithZone, zone.now assert_equal Time.utc(2000,1,1,5), zone.now.utc assert_equal Time.utc(2000), zone.now.time assert_equal zone, zone.now.time_zone end end
test_now_enforces_fall_dst_rules()
Link
# File activesupport/test/time_zone_test.rb, line 76 def test_now_enforces_fall_dst_rules with_env_tz 'US/Eastern' do zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'].dup def zone.time_now Time.at(1162098000) # equivalent to 1AM DST end assert_equal Time.utc(2006,10,29,1), zone.now.time assert_equal true, zone.now.dst? end end
test_now_enforces_spring_dst_rules()
Link
# File activesupport/test/time_zone_test.rb, line 64 def test_now_enforces_spring_dst_rules with_env_tz 'US/Eastern' do zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'].dup def zone.time_now Time.local(2006,4,2,2) # 2AM springs forward to 3AM end assert_equal Time.utc(2006,4,2,3), zone.now.time assert_equal true, zone.now.dst? end end
test_parse()
Link
# File activesupport/test/time_zone_test.rb, line 218 def test_parse zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] twz = zone.parse('1999-12-31 19:00:00') assert_equal Time.utc(1999,12,31,19), twz.time assert_equal Time.utc(2000), twz.utc assert_equal zone, twz.time_zone end
test_parse_doesnt_use_local_dst()
Link
test_parse_far_future_date_with_time_zone_offset_in_string()
Link
# File activesupport/test/time_zone_test.rb, line 241 def test_parse_far_future_date_with_time_zone_offset_in_string zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] twz = zone.parse('2050-12-31 19:00:00 -10:00') # i.e., 2050-01-01 05:00:00 UTC assert_equal [0,0,0,1,1,2051], twz.to_a[0,6] assert_equal zone, twz.time_zone end
test_parse_handles_dst_jump()
Link
# File activesupport/test/time_zone_test.rb, line 309 def test_parse_handles_dst_jump with_env_tz 'US/Eastern' do zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] twz = zone.parse('2013-03-10 02:00:00') assert_equal Time.utc(2013, 3, 10, 3, 0, 0), twz.time end end
test_parse_returns_nil_when_string_without_date_information_is_passed_in()
Link
test_parse_should_black_out_app_timezone_dst_jump()
Link
# File activesupport/test/time_zone_test.rb, line 279 def test_parse_should_black_out_app_timezone_dst_jump with_env_tz('EET') do zone = ActiveSupport::TimeZone['Pacific Time (US & Canada)'] twz = zone.parse('2012-03-11 02:29:00') assert_equal [0, 29, 3, 11, 3, 2012], twz.to_a[0,6] end end
test_parse_should_not_black_out_system_timezone_dst_jump()
Link
# File activesupport/test/time_zone_test.rb, line 271 def test_parse_should_not_black_out_system_timezone_dst_jump with_env_tz('EET') do zone = ActiveSupport::TimeZone['Pacific Time (US & Canada)'] twz = zone.parse('2012-03-25 03:29:00') assert_equal [0, 29, 3, 25, 3, 2012], twz.to_a[0,6] end end
test_parse_string_with_timezone()
Link
test_parse_with_day_omitted()
Link
# File activesupport/test/time_zone_test.rb, line 262 def test_parse_with_day_omitted with_env_tz 'US/Eastern' do zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] assert_equal Time.local(2000, 2, 1), zone.parse('Feb', Time.local(2000, 1, 1)) assert_equal Time.local(2005, 2, 1), zone.parse('Feb 2005', Time.local(2000, 1, 1)) assert_equal Time.local(2005, 2, 2), zone.parse('2 Feb 2005', Time.local(2000, 1, 1)) end end
test_parse_with_incomplete_date()
Link
# File activesupport/test/time_zone_test.rb, line 254 def test_parse_with_incomplete_date zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] zone.stub(:now, zone.local(1999,12,31)) do twz = zone.parse('19:00:00') assert_equal Time.utc(1999,12,31,19), twz.time end end
test_parse_with_javascript_date()
Link
test_parse_with_missing_time_components()
Link
# File activesupport/test/time_zone_test.rb, line 287 def test_parse_with_missing_time_components zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] zone.stub(:now, zone.local(1999, 12, 31, 12, 59, 59)) do twz = zone.parse('2012-12-01') assert_equal Time.utc(2012, 12, 1), twz.time end end
test_parse_with_old_date()
Link
test_period_for_local()
Link
test_seconds_to_utc_offset_with_colon()
Link
# File activesupport/test/time_zone_test.rb, line 409 def test_seconds_to_utc_offset_with_colon assert_equal "-06:00", ActiveSupport::TimeZone.seconds_to_utc_offset(-21_600) assert_equal "+00:00", ActiveSupport::TimeZone.seconds_to_utc_offset(0) assert_equal "+05:00", ActiveSupport::TimeZone.seconds_to_utc_offset(18_000) end
test_seconds_to_utc_offset_with_negative_offset()
Link
# File activesupport/test/time_zone_test.rb, line 421 def test_seconds_to_utc_offset_with_negative_offset assert_equal "-01:00", ActiveSupport::TimeZone.seconds_to_utc_offset(-3_600) assert_equal "-00:59", ActiveSupport::TimeZone.seconds_to_utc_offset(-3_599) assert_equal "-05:30", ActiveSupport::TimeZone.seconds_to_utc_offset(-19_800) end
test_seconds_to_utc_offset_without_colon()
Link
# File activesupport/test/time_zone_test.rb, line 415 def test_seconds_to_utc_offset_without_colon assert_equal "-0600", ActiveSupport::TimeZone.seconds_to_utc_offset(-21_600, false) assert_equal "+0000", ActiveSupport::TimeZone.seconds_to_utc_offset(0, false) assert_equal "+0500", ActiveSupport::TimeZone.seconds_to_utc_offset(18_000, false) end
test_strptime()
Link
# File activesupport/test/time_zone_test.rb, line 317 def test_strptime zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] twz = zone.strptime('1999-12-31 12:00:00', '%Y-%m-%d %H:%M:%S') assert_equal Time.utc(1999,12,31,17), twz assert_equal Time.utc(1999,12,31,12), twz.time assert_equal Time.utc(1999,12,31,17), twz.utc assert_equal zone, twz.time_zone end
test_strptime_with_almost_explicit_time_zone()
Link
# File activesupport/test/time_zone_test.rb, line 373 def test_strptime_with_almost_explicit_time_zone zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] twz = zone.strptime('1999-12-31 12:00:00 %Z', '%Y-%m-%d %H:%M:%S %%Z') assert_equal Time.utc(1999,12,31,17), twz assert_equal Time.utc(1999,12,31,12), twz.time assert_equal Time.utc(1999,12,31,17), twz.utc assert_equal zone, twz.time_zone end
test_strptime_with_day_omitted()
Link
# File activesupport/test/time_zone_test.rb, line 382 def test_strptime_with_day_omitted with_env_tz 'US/Eastern' do zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] assert_equal Time.local(2000, 2, 1), zone.strptime('Feb', '%b', Time.local(2000, 1, 1)) assert_equal Time.local(2005, 2, 1), zone.strptime('Feb 2005', '%b %Y', Time.local(2000, 1, 1)) assert_equal Time.local(2005, 2, 2), zone.strptime('2 Feb 2005', '%e %b %Y', Time.local(2000, 1, 1)) end end
test_strptime_with_explicit_time_zone_as_abbrev()
Link
# File activesupport/test/time_zone_test.rb, line 337 def test_strptime_with_explicit_time_zone_as_abbrev zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] twz = zone.strptime('1999-12-31 12:00:00 PST', '%Y-%m-%d %H:%M:%S %Z') assert_equal Time.utc(1999,12,31,20), twz assert_equal Time.utc(1999,12,31,15), twz.time assert_equal Time.utc(1999,12,31,20), twz.utc assert_equal zone, twz.time_zone end
test_strptime_with_explicit_time_zone_as_h_offset()
Link
# File activesupport/test/time_zone_test.rb, line 346 def test_strptime_with_explicit_time_zone_as_h_offset zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] twz = zone.strptime('1999-12-31 12:00:00 -08', '%Y-%m-%d %H:%M:%S %:::z') assert_equal Time.utc(1999,12,31,20), twz assert_equal Time.utc(1999,12,31,15), twz.time assert_equal Time.utc(1999,12,31,20), twz.utc assert_equal zone, twz.time_zone end
test_strptime_with_explicit_time_zone_as_hm_offset()
Link
# File activesupport/test/time_zone_test.rb, line 355 def test_strptime_with_explicit_time_zone_as_hm_offset zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] twz = zone.strptime('1999-12-31 12:00:00 -08:00', '%Y-%m-%d %H:%M:%S %:z') assert_equal Time.utc(1999,12,31,20), twz assert_equal Time.utc(1999,12,31,15), twz.time assert_equal Time.utc(1999,12,31,20), twz.utc assert_equal zone, twz.time_zone end
test_strptime_with_explicit_time_zone_as_hms_offset()
Link
# File activesupport/test/time_zone_test.rb, line 364 def test_strptime_with_explicit_time_zone_as_hms_offset zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] twz = zone.strptime('1999-12-31 12:00:00 -08:00:00', '%Y-%m-%d %H:%M:%S %::z') assert_equal Time.utc(1999,12,31,20), twz assert_equal Time.utc(1999,12,31,15), twz.time assert_equal Time.utc(1999,12,31,20), twz.utc assert_equal zone, twz.time_zone end
test_strptime_with_nondefault_time_zone()
Link
# File activesupport/test/time_zone_test.rb, line 326 def test_strptime_with_nondefault_time_zone with_tz_default ActiveSupport::TimeZone['Pacific Time (US & Canada)'] do zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] twz = zone.strptime('1999-12-31 12:00:00', '%Y-%m-%d %H:%M:%S') assert_equal Time.utc(1999,12,31,17), twz assert_equal Time.utc(1999,12,31,12), twz.time assert_equal Time.utc(1999,12,31,17), twz.utc assert_equal zone, twz.time_zone end end
test_to_s()
Link
test_to_yaml()
Link
# File activesupport/test/time_zone_test.rb, line 510 def test_to_yaml assert_equal("--- !ruby/object:ActiveSupport::TimeZone\nname: Pacific/Honolulu\n", ActiveSupport::TimeZone["Hawaii"].to_yaml) assert_equal("--- !ruby/object:ActiveSupport::TimeZone\nname: Europe/London\n", ActiveSupport::TimeZone["Europe/London"].to_yaml) end
test_today()
Link
# File activesupport/test/time_zone_test.rb, line 95 def test_today travel_to(Time.utc(2000, 1, 1, 4, 59, 59)) # 1 sec before midnight Jan 1 EST assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today travel_to(Time.utc(2000, 1, 1, 5)) # midnight Jan 1 EST assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today travel_to(Time.utc(2000, 1, 2, 4, 59, 59)) # 1 sec before midnight Jan 2 EST assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today travel_to(Time.utc(2000, 1, 2, 5)) # midnight Jan 2 EST assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today travel_back end
test_tomorrow()
Link
# File activesupport/test/time_zone_test.rb, line 107 def test_tomorrow travel_to(Time.utc(2000, 1, 1, 4, 59, 59)) # 1 sec before midnight Jan 1 EST assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].tomorrow travel_to(Time.utc(2000, 1, 1, 5)) # midnight Jan 1 EST assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].tomorrow travel_to(Time.utc(2000, 1, 2, 4, 59, 59)) # 1 sec before midnight Jan 2 EST assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].tomorrow travel_to(Time.utc(2000, 1, 2, 5)) # midnight Jan 2 EST assert_equal Date.new(2000, 1, 3), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].tomorrow travel_back end
test_travel_to_a_date()
Link
test_travel_to_travels_back_and_reraises_if_the_block_raises()
Link
test_unknown_timezones_delegation_to_tzinfo()
Link
# File activesupport/test/time_zone_test.rb, line 87 def test_unknown_timezones_delegation_to_tzinfo zone = ActiveSupport::TimeZone['America/Montevideo'] assert_equal ActiveSupport::TimeZone, zone.class assert_equal zone.object_id, ActiveSupport::TimeZone['America/Montevideo'].object_id assert_equal Time.utc(2010, 1, 31, 22), zone.utc_to_local(Time.utc(2010, 2)) # daylight saving offset -0200 assert_equal Time.utc(2010, 3, 31, 21), zone.utc_to_local(Time.utc(2010, 4)) # standard offset -0300 end
test_unknown_zone_raises_exception()
Link
test_unknown_zones_dont_store_mapping_keys()
Link
test_us_zones()
Link
test_utc_offset_is_not_cached_when_current_period_gets_stale()
Link
# File activesupport/test/time_zone_test.rb, line 398 def test_utc_offset_is_not_cached_when_current_period_gets_stale tz = ActiveSupport::TimeZone.create('Moscow') travel_to(Time.utc(2014, 10, 25, 21)) do # 1 hour before TZ change assert_equal 14400, tz.utc_offset, 'utc_offset should be initialized according to current_period' end travel_to(Time.utc(2014, 10, 25, 22)) do # after TZ change assert_equal 10800, tz.utc_offset, 'utc_offset should not be cached when current_period gets stale' end end
test_utc_offset_lazy_loaded_from_tzinfo_when_not_passed_in_to_initialize()
Link
# File activesupport/test/time_zone_test.rb, line 391 def test_utc_offset_lazy_loaded_from_tzinfo_when_not_passed_in_to_initialize tzinfo = TZInfo::Timezone.get('America/New_York') zone = ActiveSupport::TimeZone.create(tzinfo.name, nil, tzinfo) assert_equal nil, zone.instance_variable_get('@utc_offset') assert_equal(-18_000, zone.utc_offset) end
test_utc_to_local()
Link
# File activesupport/test/time_zone_test.rb, line 9 def test_utc_to_local zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] assert_equal Time.utc(1999, 12, 31, 19), zone.utc_to_local(Time.utc(2000, 1)) # standard offset -0500 assert_equal Time.utc(2000, 6, 30, 20), zone.utc_to_local(Time.utc(2000, 7)) # dst offset -0400 end
test_yaml_load()
Link
test_yesterday()
Link
# File activesupport/test/time_zone_test.rb, line 119 def test_yesterday travel_to(Time.utc(2000, 1, 1, 4, 59, 59)) # 1 sec before midnight Jan 1 EST assert_equal Date.new(1999, 12, 30), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].yesterday travel_to(Time.utc(2000, 1, 1, 5)) # midnight Jan 1 EST assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].yesterday travel_to(Time.utc(2000, 1, 2, 4, 59, 59)) # 1 sec before midnight Jan 2 EST assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].yesterday travel_to(Time.utc(2000, 1, 2, 5)) # midnight Jan 2 EST assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].yesterday travel_back end
test_z_format_strings()
Link
test_zone_compare()
Link
# File activesupport/test/time_zone_test.rb, line 453 def test_zone_compare zone1 = ActiveSupport::TimeZone['Central Time (US & Canada)'] # offset -0600 zone2 = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] # offset -0500 assert zone1 < zone2 assert zone2 > zone1 assert zone1 == zone1 end