datetime_clamping_concern.rb 361 B

1234567891011121314
  1. # frozen_string_literal: true
  2. module DatetimeClampingConcern
  3. extend ActiveSupport::Concern
  4. MIN_ISO8601_DATETIME = '0000-01-01T00:00:00Z'.to_datetime.freeze
  5. MAX_ISO8601_DATETIME = '9999-12-31T23:59:59Z'.to_datetime.freeze
  6. class_methods do
  7. def clamp_date(datetime)
  8. datetime.clamp(MIN_ISO8601_DATETIME, MAX_ISO8601_DATETIME)
  9. end
  10. end
  11. end