Class: CloudRailSi::Types::CustomDate
- Inherits:
-
SandboxObject
- Object
- SandboxObject
- CloudRailSi::Types::CustomDate
- Includes:
- Comparable
- Defined in:
- lib/cloudrail_si/types/Date.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(obj) ⇒ Object
-
#initialize(date_string = nil) ⇒ CustomDate
constructor
A new instance of CustomDate.
- #rfc_time ⇒ Object
- #time ⇒ Object
- #time=(value) ⇒ Object
Methods inherited from SandboxObject
Constructor Details
#initialize(date_string = nil) ⇒ CustomDate
Returns a new instance of CustomDate.
13 14 15 |
# File 'lib/cloudrail_si/types/Date.rb', line 13 def initialize(date_string=nil) @date = (!date_string.nil? && !date_string.empty?) ? DateTime.parse(date_string).to_time.utc.to_datetime : DateTime.now end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
11 12 13 |
# File 'lib/cloudrail_si/types/Date.rb', line 11 def date @date end |
Class Method Details
.json_create(object) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/cloudrail_si/types/Date.rb', line 40 def json_create(object) byebug cd = CustomDate.new cd.time = Integer(object['time']) return cd end |
Instance Method Details
#<=>(obj) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/cloudrail_si/types/Date.rb', line 29 def <=> (obj) raise Errors::InternalError.new("Comparing a Date with a non-Date") if (!(obj.instance_of?(CustomDate))) return -1 if (time < obj.time) return 1 if (obj.time < time) return 0 if (time === obj.time) raise Errors::InternalError.new("Comparing a Date with a non-Date") end |
#rfc_time ⇒ Object
25 26 27 |
# File 'lib/cloudrail_si/types/Date.rb', line 25 def rfc_time @date.to_time.utc.strftime("%Y-%m-%dT%H:%M:%SZ") end |
#time ⇒ Object
17 18 19 |
# File 'lib/cloudrail_si/types/Date.rb', line 17 def time @date.to_time.to_i * 1000 end |
#time=(value) ⇒ Object
21 22 23 |
# File 'lib/cloudrail_si/types/Date.rb', line 21 def time=(value) @date = Time.at(value / 1000).to_datetime end |