[ruby-list:50314] Re: Time#strftime("%A%a")
From:
dezawa <dezawa@...>
Date:
2016-04-17 10:04:19 UTC
List:
ruby-list #50314
(2016年04月10日 17:27), dezawa wrote:
> 出沢です
> 今の実装では %A,%a は英語の曜日が表示されますが、これを
> 月曜、月 というように(Localeか何かで指定した)言語に応じた表現にすること
> は予定にありますか?
googleに逃避してましたら結構需要はありそうですね。
逃避ついでに逃避してしまいました。
日本語以外は適切かどうか分かりません。
require 'date'
unless Time.method_defined?(:曜_strftime)
Weekday =
{"%曜" => "日月火水木金土",
"%曜日" => %w(日曜日 月曜日 火曜日 水曜日 木曜日 金曜日 土曜日),
"%요" => "일월화수목금토",
"%星期" => %w(星期日 星期一 星期二 星期三 星期四 星期五 星期六),
"%གཟ" => %w(གཟའ་ཉི་མ་ གཟའ་ཟླ་བ་ གཟའ་མིག་དམར་ གཟའ་ལྷག་པ་ གཟའ་ཕུར་བུ་ གཟའ་
པ་སངས་ གཟའ་སཔེན་པ་)
}
RegWeekday = /%曜日|%[曜요]|%星期|%གཟ/
class Date
alias_method :orig_strftime,:strftime
def strftime(fmt)
RegWeekday =~ fmt
return orig_strftime fmt unless $&
orig_strftime($`)+ Weekday[$&][wday] + strftime($')
end
end
class Time
alias_method :orig_strftime,:strftime
def strftime(fmt)
RegWeekday =~ fmt
return orig_strftime fmt unless $&
orig_strftime($`)+ Weekday[$&][wday] + strftime($')
end
def 曜_strftime;end
end
end
# Date.today.strftime("%Y%(%曜)%m(%요)(%星期)(%གཟ)(%曜日)")
=> "2016%(日)04(일)(星期日)(གཟའ་ཉི་མ་)(日曜日)"