Class: XMLRPC::DateTime

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of DateTime.



108
109
110
111
# File 'lib/xmlrpc/datetime.rb', line 108

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

Returns the value of attribute day



72
73
74
# File 'lib/xmlrpc/datetime.rb', line 72

def day
  @day
end

#hourObject

Returns the value of attribute hour



72
73
74
# File 'lib/xmlrpc/datetime.rb', line 72

def hour
  @hour
end

#minObject

Returns the value of attribute min



72
73
74
# File 'lib/xmlrpc/datetime.rb', line 72

def min
  @min
end

#monthObject Also known as: mon

Returns the value of attribute month



72
73
74
# File 'lib/xmlrpc/datetime.rb', line 72

def month
  @month
end

#secObject

Returns the value of attribute sec



72
73
74
# File 'lib/xmlrpc/datetime.rb', line 72

def sec
  @sec
end

#yearObject

Returns the value of attribute year



72
73
74
# File 'lib/xmlrpc/datetime.rb', line 72

def year
  @year
end

Instance Method Details

#==(o) ⇒ Object



129
130
131
# File 'lib/xmlrpc/datetime.rb', line 129

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

#to_aObject



125
126
127
# File 'lib/xmlrpc/datetime.rb', line 125

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

#to_dateObject



121
122
123
# File 'lib/xmlrpc/datetime.rb', line 121

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

#to_timeObject



113
114
115
116
117
118
119
# File 'lib/xmlrpc/datetime.rb', line 113

def to_time
  if @year >= 1970
    Time.gm(*to_a)
  else
    nil
  end
end