@@ -311,6 +311,71 @@ def test_parse_handles_dst_jump
311311 end
312312 end
313313
314+ def test_strptime
315+ zone = ActiveSupport ::TimeZone [ 'Eastern Time (US & Canada)' ]
316+ twz = zone . strptime ( '1999-12-31 12:00:00' , '%Y-%m-%d %H:%M:%S' )
317+ assert_equal Time . utc ( 1999 , 12 , 31 , 17 ) , twz
318+ assert_equal Time . utc ( 1999 , 12 , 31 , 12 ) , twz . time
319+ assert_equal Time . utc ( 1999 , 12 , 31 , 17 ) , twz . utc
320+ assert_equal zone , twz . time_zone
321+ end
322+
323+ def test_strptime_with_nondefault_time_zone
324+ with_tz_default ActiveSupport ::TimeZone [ 'Pacific Time (US & Canada)' ] do
325+ zone = ActiveSupport ::TimeZone [ 'Eastern Time (US & Canada)' ]
326+ twz = zone . strptime ( '1999-12-31 12:00:00' , '%Y-%m-%d %H:%M:%S' )
327+ assert_equal Time . utc ( 1999 , 12 , 31 , 17 ) , twz
328+ assert_equal Time . utc ( 1999 , 12 , 31 , 12 ) , twz . time
329+ assert_equal Time . utc ( 1999 , 12 , 31 , 17 ) , twz . utc
330+ assert_equal zone , twz . time_zone
331+ end
332+ end
333+
334+ def test_strptime_with_explicit_time_zone_as_abbrev
335+ zone = ActiveSupport ::TimeZone [ 'Eastern Time (US & Canada)' ]
336+ twz = zone . strptime ( '1999-12-31 12:00:00 PST' , '%Y-%m-%d %H:%M:%S %Z' )
337+ assert_equal Time . utc ( 1999 , 12 , 31 , 20 ) , twz
338+ assert_equal Time . utc ( 1999 , 12 , 31 , 15 ) , twz . time
339+ assert_equal Time . utc ( 1999 , 12 , 31 , 20 ) , twz . utc
340+ assert_equal zone , twz . time_zone
341+ end
342+
343+ def test_strptime_with_explicit_time_zone_as_h_offset
344+ zone = ActiveSupport ::TimeZone [ 'Eastern Time (US & Canada)' ]
345+ twz = zone . strptime ( '1999-12-31 12:00:00 -08' , '%Y-%m-%d %H:%M:%S %:::z' )
346+ assert_equal Time . utc ( 1999 , 12 , 31 , 20 ) , twz
347+ assert_equal Time . utc ( 1999 , 12 , 31 , 15 ) , twz . time
348+ assert_equal Time . utc ( 1999 , 12 , 31 , 20 ) , twz . utc
349+ assert_equal zone , twz . time_zone
350+ end
351+
352+ def test_strptime_with_explicit_time_zone_as_hm_offset
353+ zone = ActiveSupport ::TimeZone [ 'Eastern Time (US & Canada)' ]
354+ twz = zone . strptime ( '1999-12-31 12:00:00 -08:00' , '%Y-%m-%d %H:%M:%S %:z' )
355+ assert_equal Time . utc ( 1999 , 12 , 31 , 20 ) , twz
356+ assert_equal Time . utc ( 1999 , 12 , 31 , 15 ) , twz . time
357+ assert_equal Time . utc ( 1999 , 12 , 31 , 20 ) , twz . utc
358+ assert_equal zone , twz . time_zone
359+ end
360+
361+ def test_strptime_with_explicit_time_zone_as_hms_offset
362+ zone = ActiveSupport ::TimeZone [ 'Eastern Time (US & Canada)' ]
363+ twz = zone . strptime ( '1999-12-31 12:00:00 -08:00:00' , '%Y-%m-%d %H:%M:%S %::z' )
364+ assert_equal Time . utc ( 1999 , 12 , 31 , 20 ) , twz
365+ assert_equal Time . utc ( 1999 , 12 , 31 , 15 ) , twz . time
366+ assert_equal Time . utc ( 1999 , 12 , 31 , 20 ) , twz . utc
367+ assert_equal zone , twz . time_zone
368+ end
369+
370+ def test_strptime_with_almost_explicit_time_zone
371+ zone = ActiveSupport ::TimeZone [ 'Eastern Time (US & Canada)' ]
372+ twz = zone . strptime ( '1999-12-31 12:00:00 %Z' , '%Y-%m-%d %H:%M:%S %%Z' )
373+ assert_equal Time . utc ( 1999 , 12 , 31 , 17 ) , twz
374+ assert_equal Time . utc ( 1999 , 12 , 31 , 12 ) , twz . time
375+ assert_equal Time . utc ( 1999 , 12 , 31 , 17 ) , twz . utc
376+ assert_equal zone , twz . time_zone
377+ end
378+
314379 def test_utc_offset_lazy_loaded_from_tzinfo_when_not_passed_in_to_initialize
315380 tzinfo = TZInfo ::Timezone . get ( 'America/New_York' )
316381 zone = ActiveSupport ::TimeZone . create ( tzinfo . name , nil , tzinfo )
0 commit comments