module Icalendar # date = date-fullyear date-month date-mday # date-fullyear = 4 DIGIT # date-month = 2 DIGIT # date-mday = 2 DIGIT DATE = '(\d\d\d\d)(\d\d)(\d\d)' # time = time-hour [":"] time-minute [":"] time-second [time-secfrac] [time-zone] # time-hour = 2 DIGIT # time-minute = 2 DIGIT # time-second = 2 DIGIT # time-secfrac = "," 1*DIGIT # time-zone = "Z" / time-numzone # time-numzome = sign time-hour [":"] time-minute TIME = '(\d\d)(\d\d)(\d\d)(Z)?' # Maps to dtstart property # TODO: Look into having the DateTime library do more of the work... module Dtstart # 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. 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 # Returns the starting DateTime of an Event, Todo, Freebusy or # Timezone component. 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 end end