Class: Date
- Inherits:
-
Object
- Object
- Date
- Defined in:
- lib/ndr_support/date_and_time_extensions.rb
Overview
Extend standard Date class with our custom to_s overrides
Instance Method Summary collapse
-
#orig_to_datetime ⇒ Object
ISO date format.
- #orig_to_s ⇒ Object
- #to_datetime ⇒ Object
-
#to_iso ⇒ Object
to_iso output must be SQL safe for security reasons.
-
#to_s(format = :default) ⇒ Object
Rails 7 stops overriding to_s (without a format specification) (for performance on Ruby 3.1) cf.
Instance Method Details
#orig_to_datetime ⇒ Object
ISO date format
12 |
# File 'lib/ndr_support/date_and_time_extensions.rb', line 12 alias orig_to_datetime to_datetime |
#orig_to_s ⇒ Object
22 |
# File 'lib/ndr_support/date_and_time_extensions.rb', line 22 alias orig_to_s to_s |
#to_datetime ⇒ Object
14 15 16 17 18 19 20 |
# 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 |
#to_iso ⇒ Object
to_iso output must be SQL safe for security reasons
8 9 10 |
# File 'lib/ndr_support/date_and_time_extensions.rb', line 8 def to_iso strftime('%Y-%m-%d') end |
#to_s(format = :default) ⇒ Object
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
27 28 29 30 31 32 33 |
# 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 |