Created
December 6, 2011 16:42
-
-
Save gabrielengel/1438881 to your computer and use it in GitHub Desktop.
How strftime_nolocale works
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
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