Skip to content

Instantly share code, notes, and snippets.

@gabrielengel
Created December 6, 2011 16:42
Show Gist options
  • Save gabrielengel/1438881 to your computer and use it in GitHub Desktop.
Save gabrielengel/1438881 to your computer and use it in GitHub Desktop.
How strftime_nolocale works
require 'date'
puts Time.now.respond_to?(:strftime_nolocale)
class Time
Date::ABBR_DAYNAMES = %w(dom seg ter qua qui sex sab)
alias :strftime_nolocale :strftime
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_nolocale(format)
end
end
puts Time.now.strftime("%a")
puts Time.now.strftime_nolocale("%a")
puts Time.now.respond_to?(:strftime_nolocale)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment