mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-23 14:27:52 +00:00
moved format proc helper methods into formats module so they work
This commit is contained in:
parent
c37c3e82fa
commit
33c298163e
@ -52,5 +52,19 @@ module ValidatesTimeliness
|
||||
:iso8601 => /#{valid_date_formats[:yyyymmdd_dashes]}T#{valid_time_formats[:hhnnss_colons]}(?:Z|[-+](\d{2}):(\d{2}))?/
|
||||
}
|
||||
|
||||
def self.full_hour(hour, meridian)
|
||||
hour = hour.to_i
|
||||
if meridian.delete('.').downcase == 'am'
|
||||
hour == 12 ? 0 : hour
|
||||
else
|
||||
hour == 12 ? hour : hour + 12
|
||||
end
|
||||
end
|
||||
|
||||
def self.unambiguous_year(year, threshold=30)
|
||||
year = "#{year.to_i < threshold ? '20' : '19'}#{year}" if year.length == 2
|
||||
year.to_i
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@ -19,21 +19,6 @@ module ValidatesTimeliness
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
def full_hour(hour, meridian)
|
||||
hour = hour.to_i
|
||||
if meridian.delete('.').downcase == 'am'
|
||||
hour == 12 ? 0 : hour
|
||||
else
|
||||
hour == 12 ? hour : hour + 12
|
||||
end
|
||||
end
|
||||
|
||||
def unambiguous_year(year, threshold=30)
|
||||
year = "#{year.to_i < threshold ? '20' : '19'}#{year}" if year.length == 2
|
||||
year.to_i
|
||||
end
|
||||
|
||||
# loop through format regexps and call proc on matches if available. Allow
|
||||
# pre or post match strings if bounded is false. Lastly fills out
|
||||
# time_array to full 6 part datetime array.
|
||||
@ -43,7 +28,7 @@ module ValidatesTimeliness
|
||||
matches = regexp.match(time_string.strip)
|
||||
if !matches.nil? && (!bounded || (matches.pre_match == "" && matches.post_match == ""))
|
||||
time_array = matches[1..6] if processor.nil?
|
||||
time_array = processor.call(matches[1..6]) unless processor.nil?
|
||||
time_array = processor.call(*matches[1..6]) unless processor.nil?
|
||||
time_array = time_array.map {|i| i.to_i }
|
||||
time_array += [nil] * (6 - time_array.length)
|
||||
break
|
||||
|
||||
@ -244,7 +244,7 @@ describe ValidatesTimeliness::Validations do
|
||||
end
|
||||
|
||||
it "should have error when on boundary of :after restriction" do
|
||||
@person.birth_time = "06:00"
|
||||
@person.birth_time = "06:00am"
|
||||
@person.should_not be_valid
|
||||
@person.errors.on(:birth_time).should match(/must be after/)
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user