Class: Vobject::Vcalendar::PropertyValue::DateTimeLocal

Inherits:
PropertyValue
  • Object
show all
Includes:
Comparable
Defined in:
lib/vobject/vcalendar/propertyvalue.rb

Instance Attribute Summary

Attributes inherited from PropertyValue

#errors, #norm, #type, #value

Instance Method Summary collapse

Methods inherited from PropertyValue

#name, #to_norm

Constructor Details

#initialize(val) ⇒ DateTimeLocal

Returns a new instance of DateTimeLocal.



265
266
267
268
269
270
271
272
273
274
275
# File 'lib/vobject/vcalendar/propertyvalue.rb', line 265

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 = "datetimeLocal"
  value[:time] = if val[:zone].nil? || val[:zone].empty?
                   ::Time.local(val[:year], val[:month], val[:day], val[:hour], val[:min], val[:sec])
                 else
                   ::Time.utc(val[:year], val[:month], val[:day], val[:hour], val[:min], val[:sec])
                 end
  value[:origtime] = value[:time]
end

Instance Method Details

#<=>(another) ⇒ Object



261
262
263
# File 'lib/vobject/vcalendar/propertyvalue.rb', line 261

def <=>(another)
  value[:time] <=> another.value[:time]
end

#to_hashObject



286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/vobject/vcalendar/propertyvalue.rb', line 286

def to_hash
  ret = {
    year: value[:year],
    month: value[:month],
    day: value[:day],
    hour: value[:hour],
    min: value[:min],
    sec: value[:sec],
  }
  ret[:zone] = value[:zone] if value[:zone]
  ret
end

#to_sObject



277
278
279
280
281
282
283
# File 'lib/vobject/vcalendar/propertyvalue.rb', line 277

def to_s
  # ret = sprintf("%04d%02d%02dT%02d%02d%02d", value[:year], value[:month], value[:day], value[:hour], value[:min], value[:sec])
  ret = sprintf("%s%s%sT%s%s%s", value[:year], value[:month], value[:day], value[:hour], value[:min], value[:sec])
  zone = "Z" if value[:zone] && value[:zone] == "Z"
  ret = ret + zone if !zone.nil?
  ret
end