|
Revision 5516, 1.1 kB
(checked in by hsbt, 10 months ago)
|
|
platform/tdiary/plugin/jyear.rb: fix year expression and replace wday to day.
|
| Line | |
|---|
| 1 | # jyear.rb $Revision: 1.1 $ |
|---|
| 2 | # |
|---|
| 3 | # 西暦を和暦に変換するプラグイン。 |
|---|
| 4 | # 日記やツッコミの日付フォーマットで使う。 |
|---|
| 5 | # 「%Y」で「2005」のところを、「%K」で「平成17」と表示。 |
|---|
| 6 | # pluginに入れるだけで動作する。 |
|---|
| 7 | # |
|---|
| 8 | # Copyright (c) 2005 sasasin/SuzukiShinnosuke<sasasin@sasasin.sytes.net> |
|---|
| 9 | # You can distribute this file under the GPL. |
|---|
| 10 | # |
|---|
| 11 | |
|---|
| 12 | unless Time::new.respond_to?( :strftime_jyear_backup ) then |
|---|
| 13 | eval( <<-MODIFY_CLASS, TOPLEVEL_BINDING ) |
|---|
| 14 | class Time |
|---|
| 15 | alias strftime_jyear_backup strftime |
|---|
| 16 | def strftime( format ) |
|---|
| 17 | case self.year |
|---|
| 18 | when 0 .. 1926 |
|---|
| 19 | gengo = "昔々" |
|---|
| 20 | if self.year == 1926 && self.month == 12 && self.day >=25 then |
|---|
| 21 | gengo = "昭和元年" |
|---|
| 22 | end |
|---|
| 23 | when 1927 .. 1989 |
|---|
| 24 | jyear = self.year - 1925 |
|---|
| 25 | gengo = "昭和" + jyear.to_s |
|---|
| 26 | if self.year == 1989 && self.month == 1 && self.day >= 8 then |
|---|
| 27 | gengo = "平成元年" |
|---|
| 28 | end |
|---|
| 29 | else |
|---|
| 30 | jyear = self.year - 1988 |
|---|
| 31 | gengo = "平成" + jyear.to_s |
|---|
| 32 | end |
|---|
| 33 | strftime_jyear_backup( format.gsub( /%K/, gengo ) ) |
|---|
| 34 | end |
|---|
| 35 | end |
|---|
| 36 | MODIFY_CLASS |
|---|
| 37 | end |
|---|