class Vcard::V4_0::PropertyValue::DateTimeLocal
Public Class Methods
new(val)
click to toggle source
# File lib/vobject/vcard/v4_0/propertyvalue.rb, line 197 def initialize(val) self.value = val.clone # val consists of :time && :zone values. If :zone is empty, floating local time (i.e. system local time) is assumed self.type = "date-time" # fill in unspecified month && year && date; only for purposes of comparison val[:year] = sprintf("%04d", ::Date.today.year) unless val.has_key?(:year) val[:month] = sprintf("%02d", ::Date.today.month) unless val.has_key?(:month) val[:day] = sprintf("%02d", ::Date.today.day) unless val.has_key?(:day) val[:hour] = 0 unless val.has_key?(:hour) val[:min] = 0 unless val.has_key?(:min) val[:sec] = 0 unless val.has_key?(:sec) value[:time] = if val[:zone].empty? ::Time.utc(val[:year], val[:month], val[:day], val[:hour], val[:min], val[:sec]) else ::Time.local(val[:year], val[:month], val[:day], val[:hour], val[:min], val[:sec]) end if val[:zone] && val[:zone] != "Z" offset = val[:zone][:hour] * 3600 + val[:zone][:min] * 60 offset += val[:zone][:sec] if val[:zone][:sec] offset = -offset if val[:sign] == "-" value[:time] += offset.to_i end end
Public Instance Methods
<=>(another)
click to toggle source
# File lib/vobject/vcard/v4_0/propertyvalue.rb, line 193 def <=>(another) value[:time] <=> another.value[:time] end
to_hash()
click to toggle source
# File lib/vobject/vcard/v4_0/propertyvalue.rb, line 250 def to_hash ret = {} ret[:year] = value[:year] if value[:year] ret[:month] = value[:month] if value[:month] ret[:day] = value[:day] if value[:day] ret[:hour] = value[:hour] if value[:hour] ret[:min] = value[:min] if value[:min] ret[:sec] = value[:sec] if value[:sec] ret[:zone] = value[:zone] if value[:zone] ret end
to_s()
click to toggle source
# File lib/vobject/vcard/v4_0/propertyvalue.rb, line 221 def to_s ret = "" ret << if value[:year] value[:year] else "--" end if value[:month] ret << value[:month] elsif value[:day] ret << "-" end if value[:day] ret << value[:day] end ret << "T" ret << value[:hour] if value[:hour] ret << value[:min] if value[:min] ret << value[:sec] if value[:sec] ret << value[:zone] if value[:zone] == "Z" if value[:zone].is_a?(Hash) ret << value[:zone][:sign] ret << value[:zone][:hour] ret << value[:zone][:min] ret << value[:zone][:sec] if value[:zone][:sec] end ret end