Permalink
Browse files

UNTIL to ical - thanks Eunji Choi

  • Loading branch information...
1 parent b56e7f5 commit c11a6c9a5cdf7f18f2d56a8105790ce2efa02960 @seejohnrun committed May 10, 2011
Showing with 13 additions and 3 deletions.
  1. +3 −3 lib/ice_cube/rule.rb
  2. +5 −0 lib/ice_cube/time_util.rb
  3. +5 −0 spec/examples/to_ical_spec.rb
@@ -138,16 +138,16 @@ def to_s_base(singular, plural)
representation
end
- #TODO - until date formatting is not iCalendar here
- #get the icalendar representation of this rule logic
+ # get the icalendar representation of this rule logic
+ # Note: UNTIL dates are always in UTC as per iCalendar
def to_ical_base
representation = ''
representation << ";INTERVAL=#{@interval}" if @interval > 1
@validation_types.values.each do |v|
representation << ';' << v.send(:to_ical)
end
representation << ";COUNT=#{@occurrence_count}" if @occurrence_count
- representation << ";UNTIL=#{@until_date}" if @until_date
+ representation << ";UNTIL=#{TimeUtil.ical_utc_format(@until_date)}" if @until_date
representation
end
@@ -72,6 +72,11 @@ def self.days_in_month(date)
is_leap?(date.year) ? LeapYearMonthDays[date.month - 1] : CommonYearMonthDays[date.month - 1]
end
+ def self.ical_utc_format(time)
+ time = time.dup.utc
+ "#{time.strftime('%Y%m%dT%H%M%SZ')}" # utc time
+ end
+
def self.ical_format(time, force_utc)
time = time.dup.utc if force_utc
if time.utc?
@@ -198,5 +198,10 @@
schedule.to_ical(false).should == "DTSTART;TZID=EDT:#{time.strftime('%Y%m%dT%H%M%S')}"
schedule.to_ical(true).should == "DTSTART:#{time.utc.strftime('%Y%m%dT%H%M%S')}Z"
end
+
+ it 'should be able to serialize to ical with an until date' do
+ rule = Rule.weekly.until Time.now
+ rule.to_ical.should match /^FREQ=WEEKLY;UNTIL=\d{8}T\d{6}Z$/
+ end
end

0 comments on commit c11a6c9

Please sign in to comment.