mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
fix regexp for ISO 8601 datetimes (thanks costan)
This commit is contained in:
parent
f8b9f72693
commit
a859827af4
@ -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 hh:nn:ss
|
||||||
yyyy-mm-dd h:nn
|
yyyy-mm-dd h:nn
|
||||||
ddd mmm d hh:nn:ss zo yyyy # Ruby time string
|
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
|
NOTE: To use non-US date formats see US/EURO FORMATS section
|
||||||
|
|
||||||
|
|||||||
@ -115,7 +115,8 @@ module ValidatesTimeliness
|
|||||||
'd/m/yy h:nn',
|
'd/m/yy h:nn',
|
||||||
'ddd, dd mmm yyyy hh:nn:ss (zo|tz)', # RFC 822
|
'ddd, dd mmm yyyy hh:nn:ss (zo|tz)', # RFC 822
|
||||||
'ddd mmm d hh:nn:ss zo yyyy', # Ruby time string
|
'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
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,7 @@ describe ValidatesTimeliness::Formats do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "validation regexps" do
|
describe "validate regexps" do
|
||||||
|
|
||||||
describe "for time formats" do
|
describe "for time formats" do
|
||||||
format_tests = {
|
format_tests = {
|
||||||
@ -132,7 +132,7 @@ describe ValidatesTimeliness::Formats do
|
|||||||
time_array.should == [2000,1,1,12,13,0,0]
|
time_array.should == [2000,1,1,12,13,0,0]
|
||||||
end
|
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 = formats.parse('2000-02-01T12:13:14-10:30', :datetime, :include_offset => true)
|
||||||
time_array.should == [2000,2,1,12,13,14,0,-37800]
|
time_array.should == [2000,2,1,12,13,14,0,-37800]
|
||||||
end
|
end
|
||||||
@ -188,6 +188,18 @@ describe ValidatesTimeliness::Formats do
|
|||||||
end
|
end
|
||||||
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
|
describe "removing formats" do
|
||||||
it "should remove format from format array" do
|
it "should remove format from format array" do
|
||||||
formats.remove_formats(:time, 'h.nn_ampm')
|
formats.remove_formats(:time, 'h.nn_ampm')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user