Skip to content

Commit 2ecc372

Browse files
committed
[DOC] State timezone info in the string wins in: keyword
1 parent 045e74d commit 2ecc372

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

test/ruby/test_time.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def test_new_from_string
7777

7878
assert_equal(Time.new(2021), Time.new("2021"))
7979
assert_equal(Time.new(2021, 12, 25, in: "+09:00"), Time.new("2021-12-25+09:00"))
80+
assert_equal(Time.new(2021, 12, 25, in: "+09:00"), Time.new("2021-12-25+09:00", in: "-01:00"))
8081

8182
assert_equal(0.123456r, Time.new("2021-12-25 00:00:00.123456 +09:00").subsec)
8283
assert_equal(0.123456789r, Time.new("2021-12-25 00:00:00.123456789876 +09:00").subsec)

timev.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,12 @@ def self.at(time, subsec = false, unit = :microsecond, in: nil)
380380
# Time.new(in: '-12:00')
381381
# # => 2022-08-23 08:49:26.1941467 -1200
382382
#
383+
# Since +in:+ keyword argument just provides the default, so if the
384+
# first argument in single string form contains time zone information,
385+
# this keyword argument will be silently ignored.
386+
#
387+
# Time.new('2000-01-01 00:00:00 +0100', in: '-0500').utc_offset # => 3600
388+
#
383389
# - +precision+: maximum effective digits in sub-second part, default is 9.
384390
# More digits will be truncated, as other operations of \Time.
385391
# Ignored unless the first argument is a string.

0 commit comments

Comments
 (0)