-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
String#to_time changed defaults from :utc to :local
This commit monkey patches to_time to default back to :utc, but emits a warning if you don't pass a value in to to_time(). Any calls to `to_time` in the current code base should pass :utc. This monkey patch will make to_time backwards compatible until we find all the spots where we don't pass the right conversion type in. The default was changed [here](rails/rails@b79adc4).
- Loading branch information
1 parent
a7cb033
commit be8403d
Showing
2 changed files
with
18 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'active_support/core_ext/string/conversions' | ||
require 'active_support/deprecation' | ||
|
||
class String | ||
alias_method :old_to_time, :to_time | ||
|
||
OBJ = Object.new | ||
|
||
def to_time(form = OBJ) | ||
if form == OBJ | ||
ActiveSupport::Deprecation.warn "Rails 4 changes the default of String#to_time to local. Please pass the type of conversion you want, like to_time(:utc) or to_time(:local)", caller.drop(1) | ||
old_to_time(:utc) | ||
else | ||
old_to_time(form) | ||
end | ||
end | ||
end |