Module: BerkeleyLibrary::Util::Times

Extended by:
Times
Included in:
Times
Defined in:
lib/berkeley_library/util/times.rb

Instance Method Summary collapse

Instance Method Details

#ensure_utc(time) ⇒ Object

Returns the UTC time corresponding to time.

Parameters:

  • time (Time, Date)

    the time

Returns:

  • the UTC time corresponding to time

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
# 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