Module: ValidatesTimeliness::ValidationMethods::ClassMethods
- Defined in:
- lib/validates_timeliness/validation_methods.rb
Instance Method Summary collapse
- #parse_date_time(raw_value, type, strict = true) ⇒ Object
- #validates_date(*attr_names) ⇒ Object
- #validates_datetime(*attr_names) ⇒ Object
- #validates_time(*attr_names) ⇒ Object
Instance Method Details
#parse_date_time(raw_value, type, strict = true) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/validates_timeliness/validation_methods.rb', line 10 def parse_date_time(raw_value, type, strict=true) return nil if raw_value.blank? return raw_value if raw_value.acts_like?(:time) || raw_value.is_a?(Date) time_array = ValidatesTimeliness::Formats.parse(raw_value, type, strict) raise if time_array.nil? # Rails dummy time date part is defined as 2000-01-01 time_array[0..2] = 2000, 1, 1 if type == :time # Date.new enforces days per month, unlike Time date = Date.new(*time_array[0..2]) unless type == :time return date if type == :date # Create time object which checks time part, and return time object make_time(time_array) rescue nil end |
#validates_date(*attr_names) ⇒ Object
37 38 39 40 41 |
# File 'lib/validates_timeliness/validation_methods.rb', line 37 def validates_date(*attr_names) configuration = attr_names. configuration[:type] = :date validates_timeliness_of(attr_names, configuration) end |
#validates_datetime(*attr_names) ⇒ Object
43 44 45 46 47 |
# File 'lib/validates_timeliness/validation_methods.rb', line 43 def validates_datetime(*attr_names) configuration = attr_names. configuration[:type] = :datetime validates_timeliness_of(attr_names, configuration) end |
#validates_time(*attr_names) ⇒ Object
31 32 33 34 35 |
# File 'lib/validates_timeliness/validation_methods.rb', line 31 def validates_time(*attr_names) configuration = attr_names. configuration[:type] = :time validates_timeliness_of(attr_names, configuration) end |