Permalink
Browse files

Fixed bugs [\#4 \#6 state:committed]

  • Loading branch information...
1 parent 12c8f3c commit 034da66ca78f272d6aa8ef354094f4ea15976f1a @rubyredrick rubyredrick committed May 21, 2009
View
@@ -1,7 +1,14 @@
+=== 0.0.9
+ * Fixed http://rick_denatale.lighthouseapp.com/projects/30941/tickets/4
+ Missing comparison methods in PropertyValue::Date
+ * Fixed http://rick_denatale.lighthouseapp.com/projects/30941/tickets/6
+ Type of dtstart and dtend (DATE or DATETIME) now preserved on enumeration
=== 0.0.8
- * Fixed http://rick_denatale.lighthouseapp.com/projects/30941-ri_cal/tickets/1-occurrence-lists-not-picking-up-timewithzone-identifier#ticket-1-2
- * Fixed http://rick_denatale.lighthouseapp.com/projects/30941/tickets/2-date-property-subtraction-bug
- * Fixed http://rick_denatale.lighthouseapp.com/projects/30941/tickets/3-fwd-ri_cal-question
+ * Fixed http://rick_denatale.lighthouseapp.com/projects/30941-ri_cal/tickets/1
+ EXDATE and RDATE now pick up the timezone from DateTime, Time, and TimeWithZone values
+ * Fixed http://rick_denatale.lighthouseapp.com/projects/30941/tickets/2
+ Missing arithmetic methods in PropertyValue::Date
+ * Fixed http://rick_denatale.lighthouseapp.com/projects/30941/tickets/3
Components with no recurrence rules or rdate properties failed on enumeration, they now
will enumerate a single occurrence
View
@@ -36,6 +36,7 @@ lib/ri_cal/core_extensions/array/conversions.rb
lib/ri_cal/core_extensions/date.rb
lib/ri_cal/core_extensions/date/conversions.rb
lib/ri_cal/core_extensions/date_time.rb
+lib/ri_cal/core_extensions/date_time/conversions.rb
lib/ri_cal/core_extensions/object.rb
lib/ri_cal/core_extensions/object/conversions.rb
lib/ri_cal/core_extensions/string.rb
View
@@ -11,7 +11,7 @@ module RiCal
autoload :OccurrenceEnumerator, "#{my_dir}/ri_cal/occurrence_enumerator.rb"
# :stopdoc:
- VERSION = '0.0.8'
+ VERSION = '0.0.9'
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
@@ -22,6 +22,39 @@ def to_ri_cal_date_value(timezone_finder = nil)
def to_ri_cal_property_value(timezone_finder = nil)
to_ri_cal_date_value(timezone_finder)
end
+
+ unless defined? ActiveSupport
+ # A method to keep Time, Date and DateTime instances interchangeable on conversions.
+ # In this case, it simply returns +self+.
+ def to_date
+ self
+ end if RUBY_VERSION < '1.9'
+
+ # Converts a Date instance to a Time, where the time is set to the beginning of the day.
+ # The timezone can be either :local or :utc (default :local).
+ #
+ # ==== Examples
+ # date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
+ #
+ # date.to_time # => Sat Nov 10 00:00:00 0800 2007
+ # date.to_time(:local) # => Sat Nov 10 00:00:00 0800 2007
+ #
+ # date.to_time(:utc) # => Sat Nov 10 00:00:00 UTC 2007
+ def to_time(form = :local)
+ ::Time.send("#{form}_time", year, month, day)
+ end
+
+ # Converts a Date instance to a DateTime, where the time is set to the beginning of the day
+ # and UTC offset is set to 0.
+ #
+ # ==== Examples
+ # date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
+ #
+ # date.to_datetime # => Sat, 10 Nov 2007 00:00:00 0000
+ def to_datetime
+ ::DateTime.civil(year, month, day, 0, 0, 0, 0)
+ end if RUBY_VERSION < '1.9'
+ end
end
end
end
@@ -1,4 +1,4 @@
-require "#{File.dirname(__FILE__)}/time/conversions.rb"
+require "#{File.dirname(__FILE__)}/date_time/conversions.rb"
require "#{File.dirname(__FILE__)}/time/tzid_access.rb"
require "#{File.dirname(__FILE__)}/time/week_day_predicates.rb"
require "#{File.dirname(__FILE__)}/time/calculations.rb"
@@ -11,5 +11,5 @@ class DateTime #:nodoc:
include RiCal::CoreExtensions::Time::WeekDayPredicates
include RiCal::CoreExtensions::Time::Calculations
include RiCal::CoreExtensions::Time::TzidAccess
- include RiCal::CoreExtensions::Time::Conversions
+ include RiCal::CoreExtensions::DateTime::Conversions
end
@@ -0,0 +1,50 @@
+require 'date'
+module RiCal
+ module CoreExtensions #:nodoc:
+ module DateTime #:nodoc:
+ #- ©2009 Rick DeNatale
+ #- All rights reserved. Refer to the file README.txt for the license
+ #
+ module Conversions #:nodoc:
+ # Return an RiCal::PropertyValue::DateTime representing the receiver
+ def to_ri_cal_date_time_value(timezone_finder = nil) #:nodoc:
+ RiCal::PropertyValue::DateTime.new(
+ timezone_finder,
+ :value => strftime("%Y%m%dT%H%M%S"),
+ :params => {"TZID" => self.tzid || :default})
+ end
+
+ alias_method :to_ri_cal_date_or_date_time_value, :to_ri_cal_date_time_value #:nodoc:
+ alias_method :to_ri_cal_occurrence_list_value, :to_ri_cal_date_time_value #:nodoc:
+
+ # Return the natural ri_cal_property for this object
+ def to_ri_cal_property_value(timezone_finder = nil) #:nodoc:
+ to_ri_cal_date_time_value(timezone_finder)
+ end
+
+ # Return a copy of this object which will be interpreted as a floating time.
+ def with_floating_timezone
+ dup.set_tzid(:floating)
+ end
+
+ unless defined? ActiveSupport
+ # Converts self to a Ruby Date object; time portion is discarded
+ def to_date
+ ::Date.new(year, month, day)
+ end
+
+ # Attempts to convert self to a Ruby Time object; returns self if out of range of Ruby Time class
+ # If self has an offset other than 0, self will just be returned unaltered, since there's no clean way to map it to a Time
+ def to_time
+ self.offset == 0 ? ::Time.utc_time(year, month, day, hour, min, sec) : self
+ end
+
+ # To be able to keep Times, Dates and DateTimes interchangeable on conversions
+ def to_datetime
+ self
+ end
+ end
+ end
+ end
+ end
+end
@@ -25,6 +25,36 @@ def to_ri_cal_property_value(timezone_finder = nil) #:nodoc:
def with_floating_timezone
dup.set_tzid(:floating)
end
+
+ unless defined? ActiveSupport
+ # Converts a Time object to a Date, dropping hour, minute, and second precision.
+ #
+ # my_time = Time.now # => Mon Nov 12 22:59:51 -0500 2007
+ # my_time.to_date # => Mon, 12 Nov 2007
+ #
+ # your_time = Time.parse("1/13/2009 1:13:03 P.M.") # => Tue Jan 13 13:13:03 -0500 2009
+ # your_time.to_date # => Tue, 13 Jan 2009
+ def to_date
+ ::Date.new(year, month, day)
+ end
+
+ # A method to keep Time, Date and DateTime instances interchangeable on conversions.
+ # In this case, it simply returns +self+.
+ def to_time
+ self
+ end
+
+ # Converts a Time instance to a Ruby DateTime instance, preserving UTC offset.
+ #
+ # my_time = Time.now # => Mon Nov 12 23:04:21 -0500 2007
+ # my_time.to_datetime # => Mon, 12 Nov 2007 23:04:21 -0500
+ #
+ # your_time = Time.parse("1/13/2009 1:13:03 P.M.") # => Tue Jan 13 13:13:03 -0500 2009
+ # your_time.to_datetime # => Tue, 13 Jan 2009 13:13:03 -0500
+ def to_datetime
+ ::DateTime.civil(year, month, day, hour, min, sec, Rational(utc_offset, 86400))
+ end
+ end
end
end
end
@@ -94,7 +94,7 @@ def exclusion_for(occurrence)
# TODO: Need to research this, I beleive that this should also take the end time into account,
# but I need to research
def exclusion_match?(occurrence, exclusion)
- exclusion && occurrence[:start] == occurrence[:start]
+ exclusion && occurrence[:start] == exclusion[:start]
end
# Also exclude occurrences before the :starting date_time
@@ -172,15 +172,11 @@ def set_occurrence_properties!(occurrence) # :nodoc:
@rdate_property = nil
@exdate_property = nil
@recurrence_id_property = occurrence_start
- @dtstart_property = occurrence_start
- if occurrence_end
- @dtend_property = occurrence_end
- else
- if dtend
- my_duration = @dtend_property - @dtstart_property
- @dtend_property = occurrence_start + my_duration
- end
+ if @dtend_property && !occurrence_end
+ occurrence_end = occurrence_start + (@dtend_property - @dtstart_property)
end
+ @dtstart_property = dtstart_property.for_occurrence(occurrence_start)
+ @dtend_property = dtend_property.for_occurrence(occurrence_end) if @dtend_property
self
end
@@ -148,5 +148,17 @@ def occurrence_hash(default_duration) #:nodoc:
:end => date_time.advance(:hours => 24, :seconds => -1)}
end
end
+
+ def start_of_day?
+ true
+ end
+
+ def for_occurrence(occurrence)
+ if occurrence.start_of_day?
+ occurrence.to_ri_cal_date_value(timezone_finder)
+ else
+ occurrence.for_parent(timezone_finder)
+ end
+ end
end
end
@@ -253,8 +253,8 @@ def sec
# Return an RiCal::PropertyValue::DateTime representing the receiver.
- def to_ri_cal_date_time_value
- self
+ def to_ri_cal_date_time_value(timezone=nil)
+ for_parent(timezone)
end
def iso_year_and_week_one_start(wkst) #:nodoc:
@@ -269,6 +269,11 @@ def iso_weeks_in_year(wkst) #:nodoc:
def to_ri_cal_date_or_date_time_value(timezone_finder = nil) #:nodoc:
self.for_parent(timezone_finder)
end
+
+ # Return a Date property for this DateTime
+ def to_ri_cal_date_value(timezone_finder=nil)
+ PropertyValue::Date.new(timezone_finder, :value => @date_time_value.strftime("%Y%m%d"))
+ end
# Return the Ruby DateTime representation of the receiver
def to_datetime #:nodoc:
@@ -289,6 +294,14 @@ def ruby_value
def add_date_times_to(required_timezones) #:nodoc:
required_timezones.add_datetime(self, tzid) if has_local_timezone?
end
+
+ def start_of_day?
+ [hour, min, sec] == [0,0,0]
+ end
+
+ def for_occurrence(occurrence)
+ occurrence.to_ri_cal_date_time_value(timezone_finder)
+ end
end
end
end
@@ -309,6 +309,14 @@ def unfold(string)
@it.dtstart = Date.parse("April 22, 2009")
unfold(@it.export).should match(/^DTSTART;VALUE=DATE:20090422$/)
end
+
+ it "should properly fold on export" do
+ @it.description = "Weather report looks nice, 80 degrees and partly cloudy, so following Michael's suggestion, let's meet at the food court at Crossroads:\n\nhttp://www.shopcrossroadsplaza.c...\n"
+ export_string = @it.export
+ export_string.should match(%r(^DESCRIPTION:Weather report looks nice\\, 80 degrees and partly cloudy\\, so$))
+ export_string.should match(%r(^ following Michael's suggestion\\, let's meet at the food court at Crossr$))
+ export_string.should match(%r(^ oads:\\n\\nhttp://www.shopcrossroadsplaza\.c\.\.\.\\n))
+ end
end
if RiCal::TimeWithZone
Oops, something went wrong.

0 comments on commit 034da66

Please sign in to comment.