Module: Icalendar::Dtstart

Included in:
Event
Defined in:
lib/icalendar/helpers.rb

Overview

Maps to dtstart property TODO: Look into having the DateTime library do more of the work…

Instance Method Summary collapse

Instance Method Details

#getStartObject

Returns the starting DateTime of an Event, Todo, Freebusy or Timezone component.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/icalendar/helpers.rb', line 70

def getStart
  # If we don't have a start time then return nil.
  unless @properties.has_key?("DTSTART")
    return nil
  end
  s = @properties["DTSTART"]
  
  # If we can't parse the start time figure its bad and return nil.
  unless s =~ %r{#{DATE}}i
    return nil
  end

  # We can at least create a Date object
  year = $1
  month = $2
  day = $3

  puts "s: #{s}"
  puts "#{DATE}T#{TIME}"
  # We might be able to get the time too
  if s =~ %r{"#{DATE}T#{TIME}"}i
    hour = $5
    min = $6
    sec = $7

    puts "Hour: #{hour.to_s}"
    
    return DateTime.new(year, month, day, hour, min, sec)
  else
    return Date.new(year.to_i, month.to_i, day.to_i)
  end    
end

#setStart(start, utc = false) ⇒ Object

Set the starting DateTime of an Event, Todo, Freebusy or Timezone component. If utc is set to true then this time represents absolute time without regard for timezone information.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/icalendar/helpers.rb', line 26

def setStart(start, utc = false)
  if start.respond_to?(:year) # Date format
    s = ""

    # 4 digit year
    s << start.year.to_s
    
    # Double digit month
    s << "0" unless start.month > 9 
    s << start.month.to_s

    # Double digit day
    s << "0" unless start.day > 9 
    s << start.day.to_s
  else
    raise InvalidPropertyValue, "Cannot access year on start argument object!"
  end
  
  if start.respond_to?(:hour) # include Time format if possible
    s << "T"
    
    # Double digit hour
    s << "0" unless start.hour > 9 
    s << start.hour.to_s

    # Double digit minute
    s << "0" unless start.min > 9 
    s << start.min.to_s

    # Double digit second
    s << "0" unless start.sec > 9 
    s << start.sec.to_s
  end

  # UTC time gets a Z suffix
  if utc
    s << "Z"
  end

  @properties["DTSTART"] = s
end