Skip to content

Instantly share code, notes, and snippets.

@rrmartins
Created May 25, 2012 13:53
Show Gist options
  • Save rrmartins/2788271 to your computer and use it in GitHub Desktop.
Save rrmartins/2788271 to your computer and use it in GitHub Desktop.
Class Time
[Time, Date].each do |clazz|
eval "#{clazz}::MONTHNAMES = [nil] + %w(January February March April May June July August September October November December)"
eval "#{clazz}::DAYNAMES = %w(Sunday Monday Tuesday Wednesday Thursday Friday Saturday)"
eval "#{clazz}::ABBR_MONTHNAMES = [nil] + %w(Jan Fev Mar Abr May Jun Jul Ago Set Out Nov Dez)"
eval "#{clazz}::ABBR_DAYNAMES = %w(Sun Mon Tue Wed Thu Fri Sat)"
end
class Time
class << self
alias :org_now :now
def strftime(format)
format = format.dup
format.gsub!(/%a/, Date::ABBR_DAYNAMES[self.wday])
format.gsub!(/%A/, Date::DAYNAMES[self.wday])
format.gsub!(/%b/, Date::ABBR_MONTHNAMES[self.mon])
format.gsub!(/%B/, Date::MONTHNAMES[self.mon])
self.strftime(format)
end
# switch the month and day field for expecting US dates
def now
Time.org_now.gmtime + Time.org_now.utc_offset
end
alias :strftime_nolocale :strftime
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment