Class: XMLRPC::DateTime
- Inherits:
-
Object
- Object
- XMLRPC::DateTime
- 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
-
#day ⇒ Object
Return the value of the specified date/time component.
-
#hour ⇒ Object
Return the value of the specified date/time component.
-
#min ⇒ Object
Return the value of the specified date/time component.
-
#month ⇒ Object
(also: #mon)
Return the value of the specified date/time component.
-
#sec ⇒ Object
Return the value of the specified date/time component.
-
#year ⇒ Object
Return the value of the specified date/time component.
Instance Method Summary collapse
-
#==(o) ⇒ Object
Returns whether or not all date/time components are an array.
-
#initialize(year, month, day, hour, min, sec) ⇒ DateTime
constructor
Creates a new XMLRPC::DateTime instance with the parameters
year
,month
,day
as date andhour
,min
,sec
as time. -
#to_a ⇒ Object
Returns all date/time components in an array.
-
#to_date ⇒ Object
Return a Date object of the date which represents
self
. -
#to_time ⇒ Object
Return a Time object of the date/time which represents
self
.
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.
83 84 85 86 |
# File 'lib/xmlrpc/datetime.rb', line 83 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
#day ⇒ Object
Return the value of the specified date/time component.
20 21 22 |
# File 'lib/xmlrpc/datetime.rb', line 20 def day @day end |
#hour ⇒ Object
Return the value of the specified date/time component.
20 21 22 |
# File 'lib/xmlrpc/datetime.rb', line 20 def hour @hour end |
#min ⇒ Object
Return the value of the specified date/time component.
20 21 22 |
# File 'lib/xmlrpc/datetime.rb', line 20 def min @min end |
#month ⇒ Object Also known as: mon
Return the value of the specified date/time component.
20 21 22 |
# File 'lib/xmlrpc/datetime.rb', line 20 def month @month end |
#sec ⇒ Object
Return the value of the specified date/time component.
20 21 22 |
# File 'lib/xmlrpc/datetime.rb', line 20 def sec @sec end |
#year ⇒ Object
Return the value of the specified date/time component.
20 21 22 |
# File 'lib/xmlrpc/datetime.rb', line 20 def year @year end |
Instance Method Details
#==(o) ⇒ Object
Returns whether or not all date/time components are an array.
116 117 118 |
# File 'lib/xmlrpc/datetime.rb', line 116 def ==(o) self.to_a == Array(o) rescue false end |
#to_a ⇒ Object
Returns all date/time components in an array.
Returns [year, month, day, hour, min, sec].
111 112 113 |
# File 'lib/xmlrpc/datetime.rb', line 111 def to_a [@year, @month, @day, @hour, @min, @sec] end |
#to_date ⇒ Object
Return a Date object of the date which represents self
.
The Date object do not contain the time component (only date).
104 105 106 |
# File 'lib/xmlrpc/datetime.rb', line 104 def to_date Date.new(*to_a[0,3]) end |
#to_time ⇒ Object
Return a Time object of the date/time which represents self
. If the @year
is below 1970, this method returns nil
, because Time cannot handle years below 1970.
The timezone used is GMT.
93 94 95 96 97 98 99 |
# File 'lib/xmlrpc/datetime.rb', line 93 def to_time if @year >= 1970 Time.gm(*to_a) else nil end end |