Class: XMLRPC::DateTime

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

Overview

This class is important to handle XMLRPC dateTime.iso8601 values, correctly, because normal UNIX-dates, ie: Date, only handle dates from year 1970 on, and ruby’s native Time class handles dates without the time component.

XMLRPC::DateTime is able to store a XMLRPC dateTime.iso8601 value correctly.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year, month, day, hour, min, sec) ⇒ DateTime

Creates a new XMLRPC::DateTime instance with the parameters year, month, day as date and hour, min, sec as time.

Raises an ArgumentError if a parameter is out of range, or if year is not of the Integer type.



84
85
86
87
# File 'lib/xmlrpc/datetime.rb', line 84

def initialize(year, month, day, hour, min, sec)
  self.year, self.month, self.day = year, month, day
  self.hour, self.min, self.sec   = hour, min, sec
end

Instance Attribute Details

#dayObject

Return the value of the specified date/time component.



21
22
23
# File 'lib/xmlrpc/datetime.rb', line 21

def day
  @day
end

#hourObject

Return the value of the specified date/time component.



21
22
23
# File 'lib/xmlrpc/datetime.rb', line 21

def hour
  @hour
end

#minObject

Return the value of the specified date/time component.



21
22
23
# File 'lib/xmlrpc/datetime.rb', line 21

def min
  @min
end

#monthObject Also known as: mon

Return the value of the specified date/time component.



21
22
23
# File 'lib/xmlrpc/datetime.rb', line 21

def month
  @month
end

#secObject

Return the value of the specified date/time component.



21
22
23
# File 'lib/xmlrpc/datetime.rb', line 21

def sec
  @sec
end

#yearObject

Return the value of the specified date/time component.



21
22
23
# File 'lib/xmlrpc/datetime.rb', line 21

def year
  @year
end

Instance Method Details

#==(o) ⇒ Object

Returns whether or not all date/time components are an array.



111
112
113
# File 'lib/xmlrpc/datetime.rb', line 111

def ==(o)
  self.to_a == Array(o) rescue false
end

#to_aObject

Returns all date/time components in an array.

Returns [year, month, day, hour, min, sec].



106
107
108
# File 'lib/xmlrpc/datetime.rb', line 106

def to_a
  [@year, @month, @day, @hour, @min, @sec]
end

#to_dateObject

Return a Date object of the date which represents self.

The Date object do not contain the time component (only date).



99
100
101
# File 'lib/xmlrpc/datetime.rb', line 99

def to_date
  Date.new(*to_a[0,3])
end

#to_timeObject

Return a Time object of the date/time which represents self.

The timezone used is GMT.



92
93
94
# File 'lib/xmlrpc/datetime.rb', line 92

def to_time
  Time.gm(*to_a)
end