mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-23 06:16:44 +00:00
don't allow 0 or > 12 for meridian am hour
This commit is contained in:
parent
0ea0201051
commit
d6ddae9977
@ -209,6 +209,8 @@ module ValidatesTimeliness
|
||||
values[0..2] = dummy_date_for_time_type if type == :time
|
||||
return values
|
||||
end
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
|
||||
# Delete formats of specified type. Error raised if format not found.
|
||||
@ -255,6 +257,7 @@ module ValidatesTimeliness
|
||||
hour = hour.to_i
|
||||
return hour if meridian.nil?
|
||||
if meridian.delete('.').downcase == 'am'
|
||||
raise if hour == 0 || hour > 12
|
||||
hour == 12 ? 0 : hour
|
||||
else
|
||||
hour == 12 ? hour : hour + 12
|
||||
|
||||
@ -102,6 +102,13 @@ describe ValidatesTimeliness::Formats do
|
||||
time_array.should == [2000,1,1,12,13,14,0]
|
||||
end
|
||||
|
||||
it "should return nil if time hour is out of range for AM meridian" do
|
||||
time_array = formats.parse('13:14 am', :time, :strict => true)
|
||||
time_array.should == nil
|
||||
time_array = formats.parse('00:14 am', :time, :strict => true)
|
||||
time_array.should == nil
|
||||
end
|
||||
|
||||
it "should return date array from time string" do
|
||||
time_array = formats.parse('2000-02-01', :date, :strict => true)
|
||||
time_array.should == [2000,2,1,0,0,0,0]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user