class method
self.time_with_datetime_fallback
Ruby on Rails 4.0.13
Since v3.0.20 Last seen in v4.0.13Signature
self.time_with_datetime_fallback(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0, usec=0)
DEPRECATED: Use +Time#utc+ or +Time#local+ instead.
Returns a new Time if requested year can be accommodated by Ruby’s Time class (i.e., if year is within either 1970..2038 or 1902..2038, depending on system architecture); otherwise returns a DateTime.
Parameters
-
utc_or_localreq -
yearreq -
monthopt = 1 -
dayopt = 1 -
houropt = 0 -
minopt = 0 -
secopt = 0 -
usecopt = 0
Source
# File activesupport/lib/active_support/core_ext/time/calculations.rb, line 34
def time_with_datetime_fallback(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0, usec=0)
ActiveSupport::Deprecation.warn 'time_with_datetime_fallback is deprecated. Use Time#utc or Time#local instead', caller
time = ::Time.send(utc_or_local, year, month, day, hour, min, sec, usec)
# This check is needed because Time.utc(y) returns a time object in the 2000s for 0 <= y <= 138.
if time.year == year
time
else
::DateTime.civil_from_format(utc_or_local, year, month, day, hour, min, sec)
end
rescue
::DateTime.civil_from_format(utc_or_local, year, month, day, hour, min, sec)
end
Defined in activesupport/lib/active_support/core_ext/time/calculations.rb line 34
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Time