class Date

Extend standard Date class with our custom to_s overrides

Public Instance Methods

orig_to_datetime()
Alias for: to_datetime
orig_to_s(format = :default)
Alias for: to_s
to_datetime() click to toggle source
# File lib/ndr_support/date_and_time_extensions.rb, line 14
def to_datetime
  # Default timezone for Date is GMT, not local timezone
  default_timezone = ActiveRecord.default_timezone
  return in_time_zone.to_datetime if default_timezone == :local

  orig_to_datetime
end
Also aliased as: orig_to_datetime
to_iso() click to toggle source

to_iso output must be SQL safe for security reasons

# File lib/ndr_support/date_and_time_extensions.rb, line 8
def to_iso
  strftime('%Y-%m-%d')
end
to_s(format = :default) click to toggle source

Rails 7 stops overriding to_s (without a format specification) (for performance on Ruby 3.1) cf. activesupport-7.0.4/lib/active_support/core_ext/date/deprecated_conversions.rb We keep overriding this for compatibility

# File lib/ndr_support/date_and_time_extensions.rb, line 27
def to_s(format = :default)
  if format == :default
    DATE_FORMATS.key?(:default) ? to_fs(:default) : orig_to_s
  else
    orig_to_s(format)
  end
end
Also aliased as: orig_to_s