spec/formats_spec.rb in adzap-validates_timeliness-2.0.0 vs spec/formats_spec.rb in adzap-validates_timeliness-2.1.0
- old
+ new
@@ -153,9 +153,31 @@
time_array = formats.parse('2000-02-01 12:13', :datetime, :format => 'yyyy-mm-dd hh:nn:ss')
time_array.should be_nil
end
end
+ describe "parsing date with ambiguous year" do
+ it "should return year in current century if year below threshold" do
+ time_array = formats.parse('01-02-29', :date)
+ time_array.should == [2029,2,1,0,0,0,0]
+ end
+
+ it "should return year in last century if year at or above threshold" do
+ time_array = formats.parse('01-02-30', :date)
+ time_array.should == [1930,2,1,0,0,0,0]
+ end
+
+ it "should allow custom threshold" do
+ default = ValidatesTimeliness::Formats.ambiguous_year_threshold
+ ValidatesTimeliness::Formats.ambiguous_year_threshold = 40
+ time_array = formats.parse('01-02-39', :date)
+ time_array.should == [2039,2,1,0,0,0,0]
+ time_array = formats.parse('01-02-40', :date)
+ time_array.should == [1940,2,1,0,0,0,0]
+ ValidatesTimeliness::Formats.ambiguous_year_threshold = default
+ end
+ end
+
describe "removing formats" do
it "should remove format from format array" do
formats.remove_formats(:time, 'h.nn_ampm')
formats.time_formats.should_not include("h o'clock")
end