Class: TypedEAV::Field::DateTime
- Inherits:
-
RangeBounded
- Object
- ActiveRecord::Base
- ApplicationRecord
- Base
- RangeBounded
- TypedEAV::Field::DateTime
- Defined in:
- app/models/typed_eav/field/date_time.rb
Overview
DateTime-typed field with optional min_datetime/max_datetime guards. Declares its own ‘datetime_value` storage and `:min_datetime`/`:max_datetime` `store_accessor`. `validate_datetime_range` is inherited from `Field::RangeBounded`.
Latent-bug fix (per ADR-0004): the ‘validates :max_datetime, comparison: { greater_than_or_equal_to: :min_datetime }` macro now applies here (previously only Integer/Decimal carried it). A DateTime field configured with `max_datetime < min_datetime` fails at field-save instead of saving silently.
Constant Summary
Constants inherited from Base
Constants included from TypedStorage
TypedStorage::DEFAULT_OPERATORS_BY_COLUMN, TypedStorage::FALLBACK_OPERATORS
Instance Method Summary collapse
Methods inherited from Base
#allowed_option_values, #array_field?, #backfill_default!, #clear_option_cache!, #default_value, #default_value=, export_schema, #field_type_name, import_schema, #insert_at, #move_higher, #move_lower, #move_to_bottom, #move_to_top, #optionable?
Methods included from TypedStorage
#after_snapshot, #apply_default, #before_snapshot, #read_value, #value_changed?, #write_value
Instance Method Details
#cast(raw) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/typed_eav/field/date_time.rb', line 25 def cast(raw) return [nil, false] if raw.nil? return [raw, false] if raw.is_a?(::Time) result = ::Time.zone.parse(raw.to_s) if result.nil? [nil, !raw.to_s.strip.empty?] else [result, false] end rescue ArgumentError [nil, true] end |
#validate_typed_value(record, val) ⇒ Object
39 40 41 |
# File 'app/models/typed_eav/field/date_time.rb', line 39 def validate_typed_value(record, val) validate_datetime_range(record, val) end |