Skip to content

Instantly share code, notes, and snippets.

@KellyLSB
Created December 10, 2013 19:04
Show Gist options
  • Save KellyLSB/7896177 to your computer and use it in GitHub Desktop.
Save KellyLSB/7896177 to your computer and use it in GitHub Desktop.
---
us: %m/%d/%Y
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