diff --git a/README b/README index dc29d78..95d6aa4 100644 --- a/README +++ b/README @@ -231,15 +231,15 @@ an example of using Chronis instead. Put this into a file in the lib directory. class ActiveRecord::Base - def self.timeliness_date_time_parse(raw_value, type) - + def self.parse_date_time(raw_value, type) + end end == CREDITS: -* Adam Meehan (http://duckpunching.com/) +* Adam Meehan (adam.meehan@gmail.com, http://duckpunching.com/) * Jonathan Viney (http://workingwithrails.com/person/4985-jonathan-viney) For his validates_date_time plugin which I have used before this plugin and diff --git a/lib/validates_timeliness/validations.rb b/lib/validates_timeliness/validations.rb index bdde360..1c9edc0 100644 --- a/lib/validates_timeliness/validations.rb +++ b/lib/validates_timeliness/validations.rb @@ -24,8 +24,9 @@ module ValidatesTimeliness # Chronic. Just return nil for an invalid value and a Time object for a # valid parsed value. # - # Remember Rails, since version 2, will automatically handle the fallback - # to a DateTime when you create a time which is out of range. + # Remember to attempt fallback to back to a DateTime if the Time object is + # out of range. Range for Ruby Time class on 32-bit *nix is down to about + # 1902-01-01 and 1970-01-01 for Windows. def timeliness_date_time_parse(raw_value, type, strict=true) return raw_value.to_time if raw_value.acts_like?(:time) || raw_value.is_a?(Date) @@ -44,11 +45,11 @@ module ValidatesTimeliness Date.new(*time_array[0..2]) unless type == :time # Check time part, and return time object - Time.local(*time_array) + Time.local(*time_array) rescue DateTime.new(*time_array[0..5]) rescue nil end - + alias_method :parse_date_time, :timeliness_date_time_parse # The main validation method which can be used directly or called through # the other specific type validation methods. diff --git a/spec/formats_spec.rb b/spec/formats_spec.rb index 44a1793..f1d56a8 100644 --- a/spec/formats_spec.rb +++ b/spec/formats_spec.rb @@ -186,6 +186,7 @@ describe ValidatesTimeliness::Formats do after do formats.time_formats << 'h.nn_ampm' + # reload class instead end end @@ -223,6 +224,7 @@ describe ValidatesTimeliness::Formats do after do formats.time_formats.delete("h o'clock") formats.time_formats.delete("ss:hh:nn") + # reload class instead end end @@ -231,13 +233,12 @@ describe ValidatesTimeliness::Formats do time_array = formats.extract_date_time_values('01/02/2000', :date) time_array.should == [2000, 1, 2,nil,nil,nil,nil] formats.remove_us_formats - puts formats.datetime_formats.inspect time_array = formats.extract_date_time_values('01/02/2000', :date) time_array.should == [2000, 2, 1,nil,nil,nil,nil] end after do - + # reload class end end diff --git a/spec/validations_spec.rb b/spec/validations_spec.rb index b5da8c7..5c90656 100644 --- a/spec/validations_spec.rb +++ b/spec/validations_spec.rb @@ -53,12 +53,10 @@ describe ValidatesTimeliness::Validations do @person.should be_valid end - # What is going on? No fall back. it "should be valid with values before out of Time range" do @person.birth_date_and_time = "1890-01-31 12:12:12" @person.birth_date = "1890-01-31" @person.birth_time = "23:59:59" - puts @person.errors.inspect @person.should be_valid end