Created
December 10, 2013 19:04
-
-
Save KellyLSB/7896177 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
us: %m/%d/%Y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Date::DATE_FORMATS.merge!(YAML.load_file(Rails.root.join('config', 'date_formats.yml'))) | |
class String | |
def to_time(format = :db) | |
Time.strptime(self, Date::DATE_FORMATS[format]) | |
end | |
def to_date(format = :db) | |
Time.strptime(self, Date::DATE_FORMATS[format]).to_date | |
end | |
end | |
class Time | |
def to_s(format = nil) | |
return super unless format | |
strftime(Date::DATE_FORMATS[format]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment