diff --git a/CHANGELOG b/CHANGELOG index ad9afbf..2e6e986 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +[2008-11-13] + - allow uppercase meridian to be valid + [2008-10-28] - 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. diff --git a/lib/validates_timeliness/formats.rb b/lib/validates_timeliness/formats.rb index 8ebd655..457f084 100644 --- a/lib/validates_timeliness/formats.rb +++ b/lib/validates_timeliness/formats.rb @@ -123,7 +123,7 @@ module ValidatesTimeliness { 'ss' => [ /s{2,}/, '(\d{2})', :sec ] }, { 's' => [ /s{1}/, '(\d{1,2})', :sec ] }, { 'u' => [ /u{1,}/, '(\d{1,6})', :usec ] }, - { 'ampm' => [ /ampm/, '((?:a|p)\.?m\.?)', :meridian ] }, + { 'ampm' => [ /ampm/, '((?:[aApP])\.?[mM]\.?)', :meridian ] }, { 'zo' => [ /zo/, '(?:[+-]\d{2}:?\d{2})'] }, { 'tz' => [ /tz/, '(?:[A-Z]{1,4})' ] }, { '_' => [ /_/, '\s?' ] } diff --git a/spec/formats_spec.rb b/spec/formats_spec.rb index e176ad6..d3b691d 100644 --- a/spec/formats_spec.rb +++ b/spec/formats_spec.rb @@ -13,11 +13,11 @@ describe ValidatesTimeliness::Formats do end 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 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 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', '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_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 regexp = generate_regexp(format) values[:pass].each {|value| value.should match(regexp)}