lib/validates_timeliness/formats.rb in adzap-validates_timeliness-1.1.5 vs lib/validates_timeliness/formats.rb in adzap-validates_timeliness-1.1.6
- old
+ new
@@ -166,13 +166,13 @@
matches = nil
exp, processor = expression_set(type, string).find do |regexp, proc|
full = /\A#{regexp}\Z/ if strict
full ||= case type
- when :datetime then /\A#{regexp}\Z/
- when :date then /\A#{regexp}/
- else /#{regexp}\Z/
+ when :date then /\A#{regexp}/
+ when :time then /#{regexp}\Z/
+ when :datetime then /\A#{regexp}\Z/
end
matches = full.match(string.strip)
end
processor.call(*matches[1..7]) if matches
end
@@ -266,21 +266,21 @@
# Pick expression set and combine date and datetimes for
# datetime attributes to allow date string as datetime
def expression_set(type, string)
case type
- when :date
- date_expressions
- when :time
- time_expressions
- when :datetime
- # gives a speed-up for date string as datetime attributes
- if string.length < 11
- date_expressions + datetime_expressions
- else
- datetime_expressions + date_expressions
- end
+ when :date
+ date_expressions
+ when :time
+ time_expressions
+ when :datetime
+ # gives a speed-up for date string as datetime attributes
+ if string.length < 11
+ date_expressions + datetime_expressions
+ else
+ datetime_expressions + date_expressions
+ end
end
end
def full_hour(hour, meridian)
hour = hour.to_i
@@ -314,5 +314,7 @@
(".#{usec}".to_f * 1_000_000).to_i
end
end
end
end
+
+ValidatesTimeliness::Formats.compile_format_expressions