未验证 提交 4a797074 编写于 作者: A Andrew White 提交者: GitHub

Merge pull request #35659 from rails/fix-time-advance-with-historical-dates

Fix Time#advance to work with dates before 1001-03-07
* Fix `Time#advance` to work with dates before 1001-03-07
Before:
Time.utc(1001, 3, 6).advance(years: -1) # => 1000-03-05 00:00:00 UTC
After
Time.utc(1001, 3, 6).advance(years: -1) # => 1000-03-06 00:00:00 UTC
Note that this doesn't affect `DateTime#advance` as that doesn't use a proleptic calendar.
*Andrew White*
* In Zeitwerk mode, engines are now managed by the `main` autoloader. Engines may reference application constants, if the application is reloaded and we do not reload engines, they won't use the reloaded application code.
*Xavier Noria*
......
......@@ -170,8 +170,7 @@ def advance(options)
options[:hours] = options.fetch(:hours, 0) + 24 * partial_days
end
d = to_date.advance(options)
d = d.gregorian if d.julian?
d = to_date.gregorian.advance(options)
time_advanced_by_date = change(year: d.year, month: d.month, day: d.day)
seconds_to_advance = \
options.fetch(:seconds, 0) +
......
......@@ -514,6 +514,8 @@ def test_advance_gregorian_proleptic
assert_equal Time.local(1582, 10, 15, 15, 15, 10), Time.local(1582, 10, 14, 15, 15, 10).advance(days: 1)
assert_equal Time.local(1582, 10, 5, 15, 15, 10), Time.local(1582, 10, 4, 15, 15, 10).advance(days: 1)
assert_equal Time.local(1582, 10, 4, 15, 15, 10), Time.local(1582, 10, 5, 15, 15, 10).advance(days: -1)
assert_equal Time.local(999, 10, 4, 15, 15, 10), Time.local(1000, 10, 4, 15, 15, 10).advance(years: -1)
assert_equal Time.local(1000, 10, 4, 15, 15, 10), Time.local(999, 10, 4, 15, 15, 10).advance(years: 1)
end
def test_last_week
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册