Method: TZInfo::TimeOrDateTime#add_with_convert
- Defined in:
- lib/tzinfo/time_or_datetime.rb
#add_with_convert(seconds) ⇒ Object
Similar to the + operator, but converts to a DateTime based TimeOrDateTime where the Time or Integer timestamp to go out of the allowed range for a Time, converts to a DateTime based TimeOrDateTime.
Note that the range of Time varies based on the platform.
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/tzinfo/time_or_datetime.rb', line 271 def add_with_convert(seconds) if seconds == 0 self else if @orig.is_a?(DateTime) TimeOrDateTime.new(@orig + OffsetRationals.rational_for_offset(seconds)) else # A Time or timestamp. result = to_i + seconds if ((result > 2147483647 || result < -2147483648) && !RubyCoreSupport.time_supports_64bit) || (result < 0 && !RubyCoreSupport.time_supports_negative) result = TimeOrDateTime.new(to_datetime + OffsetRationals.rational_for_offset(seconds)) else result = TimeOrDateTime.new(@orig + seconds) end end end end |