Class: Time
- Inherits:
-
Object
- Object
- Time
- 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
-
.input(datetime) ⇒ void
Store the input datetime as a Time object.
-
.output(datetime) ⇒ String
Format the datetime into a ISO 8601 formatted string.
Instance Method Summary collapse
-
#to_s ⇒ String
The datetime in ISO 8601 format.
Class Method Details
.input(datetime) ⇒ void
This method returns an undefined value.
Returns Store the input datetime as a Time object.
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.
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_s ⇒ String
Returns The datetime in ISO 8601 format.
16 17 18 |
# File 'lib/monkey_patches.rb', line 16 def to_s self.utc.iso8601 end |