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.
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
#day ⇒ Object
Return the value of the specified date/time component.
21 22 23 |
# File 'lib/xmlrpc/datetime.rb', line 21 def day @day end |
#hour ⇒ Object
Return the value of the specified date/time component.
21 22 23 |
# File 'lib/xmlrpc/datetime.rb', line 21 def hour @hour end |
#min ⇒ Object
Return the value of the specified date/time component.
21 22 23 |
# File 'lib/xmlrpc/datetime.rb', line 21 def min @min end |
#month ⇒ Object 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 |
#sec ⇒ Object
Return the value of the specified date/time component.
21 22 23 |
# File 'lib/xmlrpc/datetime.rb', line 21 def sec @sec end |
#year ⇒ Object
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_a ⇒ Object
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_date ⇒ Object
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_time ⇒ Object
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 |