module BerkeleyLibrary::Util::Times

Public Instance Methods

ensure_utc(time) click to toggle source

@param time [Time, Date] the time @return the UTC time corresponding to `time`

# File lib/berkeley_library/util/times.rb, line 12
def ensure_utc(time)
  return unless time
  return time if time.respond_to?(:utc?) && time.utc?
  return time.getutc if time.respond_to?(:getutc)
  return time.to_time.getutc if time.respond_to?(:to_time)

  raise ArgumentError, "Not a date or time: #{time.inspect}"
end