|
Revision 1, 0.9 KB
(checked in by dema, 8 years ago)
|
|
Initial import
|
| Line | |
|---|
| 1 | module ActiveSupport #:nodoc: |
|---|
| 2 | module CoreExtensions #:nodoc: |
|---|
| 3 | module Date #:nodoc: |
|---|
| 4 | # Getting dates in different convenient string representations and other objects |
|---|
| 5 | module Conversions |
|---|
| 6 | def self.append_features(klass) #:nodoc: |
|---|
| 7 | super |
|---|
| 8 | klass.send(:alias_method, :to_default_s, :to_s) |
|---|
| 9 | klass.send(:alias_method, :to_s, :to_formatted_s) |
|---|
| 10 | end |
|---|
| 11 | |
|---|
| 12 | def to_formatted_s(format = :default) |
|---|
| 13 | case format |
|---|
| 14 | when :default then to_default_s |
|---|
| 15 | when :short then strftime("%e %b").strip |
|---|
| 16 | when :long then strftime("%B %e, %Y").strip |
|---|
| 17 | end |
|---|
| 18 | end |
|---|
| 19 | |
|---|
| 20 | # To be able to keep Dates and Times interchangeable on conversions |
|---|
| 21 | def to_date |
|---|
| 22 | self |
|---|
| 23 | end |
|---|
| 24 | |
|---|
| 25 | def to_time(form = :local) |
|---|
| 26 | ::Time.send(form, year, month, day) |
|---|
| 27 | end |
|---|
| 28 | end |
|---|
| 29 | end |
|---|
| 30 | end |
|---|
| 31 | end |
|---|