mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 08:33:58 +02:00
Support %U/%u/%W/%w/%V/%g/%G formats in Time.strptime
Most of these formats were documented as supported, but were not actually supported. Document that %g and %G are supported. If %U/%W is specified without yday and mon/mday are not specified, then Date.strptime is used to get the appropriate yday. If cwyear is specifier without the year, or cwday and cweek are specified without mday and mon, then use Date.strptime and convert the resulting value to Time, since Time.make_time cannot handle those conversions Fixes [Bug #9836] Fixes [Bug #14241]
This commit is contained in:
parent
8f1062127e
commit
a9d4f2d03c
Notes:
git
2019-11-21 10:32:50 +09:00
2 changed files with 23 additions and 1 deletions
|
@ -528,6 +528,17 @@ class TestTimeExtension < Test::Unit::TestCase # :nodoc:
|
|||
assert_equal(15, t.hour)
|
||||
end
|
||||
|
||||
def test_strptime_wuvg
|
||||
assert_equal(Time.local(2019, 1, 30), Time.strptime("3 4 2019", "%w %W %Y"))
|
||||
assert_equal(Time.local(2019, 2, 7), Time.strptime("4 5 2019", "%u %U %Y"))
|
||||
assert_equal(Time.local(2019, 1, 28), Time.strptime("4 2019", "%W %Y"))
|
||||
assert_equal(Time.local(2019, 2, 3), Time.strptime("5 2019", "%U %Y"))
|
||||
assert_equal(Time.local(2019, 1, 1), Time.strptime("1 2 2019", "%V %w %G"))
|
||||
assert_equal(Time.local(2016, 1, 1), Time.strptime("53 5 15", "%V %w %g"))
|
||||
assert_equal(Time.local(2018, 12, 31), Time.strptime("1 2019", "%V %G"))
|
||||
assert_equal(Time.local(2015, 12, 28), Time.strptime("53 15", "%V %g"))
|
||||
end
|
||||
|
||||
def test_nsec
|
||||
assert_equal(123456789, Time.parse("2000-01-01T00:00:00.123456789+00:00").tv_nsec)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue