fix regexp for ISO 8601 datetimes (thanks costan)

This commit is contained in:
Adam Meehan 2009-12-23 13:06:32 +11:00
parent f8b9f72693
commit a859827af4
3 changed files with 118 additions and 104 deletions

View File

@ -165,7 +165,8 @@ NOTE: To use non-US date formats see US/EURO FORMATS section
yyyy-mm-dd hh:nn:ss
yyyy-mm-dd h:nn
ddd mmm d hh:nn:ss zo yyyy # Ruby time string
yyyy-mm-ddThh:nn:ss(?:Z|zo) # ISO 8601
yyyy-mm-ddThh:nn:ssZ # ISO 8601 without zone offset
yyyy-mm-ddThh:nn:sszo # ISO 8601 with zone offset
NOTE: To use non-US date formats see US/EURO FORMATS section

View File

@ -115,7 +115,8 @@ module ValidatesTimeliness
'd/m/yy h:nn',
'ddd, dd mmm yyyy hh:nn:ss (zo|tz)', # RFC 822
'ddd mmm d hh:nn:ss zo yyyy', # Ruby time string
'yyyy-mm-ddThh:nn:ss(?:Z|zo)' # iso 8601
'yyyy-mm-ddThh:nn:ssZ', # iso 8601 without zone offset
'yyyy-mm-ddThh:nn:sszo' # iso 8601 with zone offset
]

View File

@ -32,7 +32,7 @@ describe ValidatesTimeliness::Formats do
end
end
describe "validation regexps" do
describe "validate regexps" do
describe "for time formats" do
format_tests = {
@ -132,7 +132,7 @@ describe ValidatesTimeliness::Formats do
time_array.should == [2000,1,1,12,13,0,0]
end
it "should return zone offset when :include_offset options is true" do
it "should return zone offset when :include_offset option is true" do
time_array = formats.parse('2000-02-01T12:13:14-10:30', :datetime, :include_offset => true)
time_array.should == [2000,2,1,12,13,14,0,-37800]
end
@ -188,6 +188,18 @@ describe ValidatesTimeliness::Formats do
end
end
describe "parse ISO8601 datetime" do
it "should return array without zone offset when no offset in string" do
time_array = formats.parse('2000-02-01T12:13:14Z', :datetime, :strict => true)
time_array.should == [2000,2,1,12,13,14,0]
end
it "should return array with zone offset when offset in string" do
time_array = formats.parse('2000-02-01T12:13:14+10:00', :datetime, :strict => true)
time_array.should == [2000,2,1,12,13,14,0,36000]
end
end
describe "removing formats" do
it "should remove format from format array" do
formats.remove_formats(:time, 'h.nn_ampm')