allow uppercase meridian to be valid

This commit is contained in:
Adam Meehan 2008-11-13 10:26:16 +11:00
parent 604a792e25
commit 889bdc3ae3
3 changed files with 9 additions and 6 deletions

View File

@ -1,3 +1,6 @@
[2008-11-13]
- allow uppercase meridian to be valid
[2008-10-28] [2008-10-28]
- fixed bug when dirty attributes not reflecting change when attribute changed from time value to nil [reported by Brad (pvjq)] - fixed bug when dirty attributes not reflecting change when attribute changed from time value to nil [reported by Brad (pvjq)]
- fixes for Rails 2.2 compatibility. Will refactor in to Rails version specific branches in the future. - fixes for Rails 2.2 compatibility. Will refactor in to Rails version specific branches in the future.

View File

@ -123,7 +123,7 @@ module ValidatesTimeliness
{ 'ss' => [ /s{2,}/, '(\d{2})', :sec ] }, { 'ss' => [ /s{2,}/, '(\d{2})', :sec ] },
{ 's' => [ /s{1}/, '(\d{1,2})', :sec ] }, { 's' => [ /s{1}/, '(\d{1,2})', :sec ] },
{ 'u' => [ /u{1,}/, '(\d{1,6})', :usec ] }, { 'u' => [ /u{1,}/, '(\d{1,6})', :usec ] },
{ 'ampm' => [ /ampm/, '((?:a|p)\.?m\.?)', :meridian ] }, { 'ampm' => [ /ampm/, '((?:[aApP])\.?[mM]\.?)', :meridian ] },
{ 'zo' => [ /zo/, '(?:[+-]\d{2}:?\d{2})'] }, { 'zo' => [ /zo/, '(?:[+-]\d{2}:?\d{2})'] },
{ 'tz' => [ /tz/, '(?:[A-Z]{1,4})' ] }, { 'tz' => [ /tz/, '(?:[A-Z]{1,4})' ] },
{ '_' => [ /_/, '\s?' ] } { '_' => [ /_/, '\s?' ] }

View File

@ -13,11 +13,11 @@ describe ValidatesTimeliness::Formats do
end end
it "should generate regexp for time with meridian" do it "should generate regexp for time with meridian" do
generate_regexp_str('hh:nn:ss ampm').should == '/(\d{2}):(\d{2}):(\d{2}) ((?:a|p)\.?m\.?)/' generate_regexp_str('hh:nn:ss ampm').should == '/(\d{2}):(\d{2}):(\d{2}) ((?:[aApP])\.?[mM]\.?)/'
end end
it "should generate regexp for time with meridian and optional space between" do it "should generate regexp for time with meridian and optional space between" do
generate_regexp_str('hh:nn:ss_ampm').should == '/(\d{2}):(\d{2}):(\d{2})\s?((?:a|p)\.?m\.?)/' generate_regexp_str('hh:nn:ss_ampm').should == '/(\d{2}):(\d{2}):(\d{2})\s?((?:[aApP])\.?[mM]\.?)/'
end end
it "should generate regexp for time with single or double digits" do it "should generate regexp for time with single or double digits" do
@ -83,13 +83,13 @@ describe ValidatesTimeliness::Formats do
'h.nn' => {:pass => ['2.12', '12.12'], :fail => ['2.1', '12:12']}, 'h.nn' => {:pass => ['2.12', '12.12'], :fail => ['2.1', '12:12']},
'h nn' => {:pass => ['2 12', '12 12'], :fail => ['2 1', '2.12', '12:12']}, 'h nn' => {:pass => ['2 12', '12 12'], :fail => ['2 1', '2.12', '12:12']},
'h-nn' => {:pass => ['2-12', '12-12'], :fail => ['2-1', '2.12', '12:12']}, 'h-nn' => {:pass => ['2-12', '12-12'], :fail => ['2-1', '2.12', '12:12']},
'h:nn_ampm' => {:pass => ['2:12am', '2:12 pm'], :fail => ['1:2am', '1:12 pm', '2.12am']}, 'h:nn_ampm' => {:pass => ['2:12am', '2:12 pm', '2:12 AM', '2:12PM'], :fail => ['1:2am', '1:12 pm', '2.12am']},
'h.nn_ampm' => {:pass => ['2.12am', '2.12 pm'], :fail => ['1:2am', '1:12 pm', '2:12am']}, 'h.nn_ampm' => {:pass => ['2.12am', '2.12 pm'], :fail => ['1:2am', '1:12 pm', '2:12am']},
'h nn_ampm' => {:pass => ['2 12am', '2 12 pm'], :fail => ['1 2am', '1 12 pm', '2:12am']}, 'h nn_ampm' => {:pass => ['2 12am', '2 12 pm'], :fail => ['1 2am', '1 12 pm', '2:12am']},
'h-nn_ampm' => {:pass => ['2-12am', '2-12 pm'], :fail => ['1-2am', '1-12 pm', '2:12am']}, 'h-nn_ampm' => {:pass => ['2-12am', '2-12 pm'], :fail => ['1-2am', '1-12 pm', '2:12am']},
'h_ampm' => {:pass => ['2am', '2 am', '12 pm'], :fail => ['1.am', '12 pm', '2:12am']}, 'h_ampm' => {:pass => ['2am', '2 am', '12 pm'], :fail => ['1.am', '12 pm', '2:12am']},
} }
format_tests.each do |format, values| format_tests.each do |format, values|
it "should correctly validate times in format '#{format}'" do it "should correctly validate times in format '#{format}'" do
regexp = generate_regexp(format) regexp = generate_regexp(format)
values[:pass].each {|value| value.should match(regexp)} values[:pass].each {|value| value.should match(regexp)}