Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/monkey_patches.rb

Overview

Make the default output from a Time variable be formatted in ISO 8601 format

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.input(datetime) ⇒ void

This method returns an undefined value.

Returns Store the input datetime as a Time object.

Parameters:

  • datetime (Time, String, Nil)

    The input datetime



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/monkey_patches.rb', line 22

def self.input(datetime)
  case datetime
    when nil
      nil
    when ""
      nil
    when String
      Time.parse(datetime)
    when Time
      datetime
    else
      raise "unknown time format #{datetime.inspect}"
  end
end

.output(datetime) ⇒ String

Returns Format the datetime into a ISO 8601 formatted string.

Parameters:

  • datetime (Time, String, Nil)

    The datetime value to output

Returns:

  • (String)

    Format the datetime into a ISO 8601 formatted string



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/monkey_patches.rb', line 39

def self.output(datetime)
  case datetime
    when nil
      nil
    when String
      Time.parse(datetime).utc.iso8601
    when Time
      datetime.utc.iso8601
    else
      raise "unknown time format #{datetime.inspect}"
  end
end

Instance Method Details

#to_sString

Returns The datetime in ISO 8601 format.

Returns:

  • (String)

    The datetime in ISO 8601 format



16
17
18
# File 'lib/monkey_patches.rb', line 16

def to_s
  self.utc.iso8601
end