Class: CloudRailSi::Types::CustomDate

Inherits:
SandboxObject show all
Includes:
Comparable
Defined in:
lib/cloudrail_si/types/Date.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SandboxObject

#get, #set

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

#dateObject

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_timeObject



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

#timeObject



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