15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/tax_jp/gengou.rb', line 15
def self.to_wareki(date, only_date: false, format: '%y年%m月%d日')
return nil unless date.present?
date = TaxJp::Utils.convert_to_date(date)
target_date = nil
@@_gengou.keys.each do |start_date|
target_date = TaxJp::Utils.convert_to_date(start_date)
break if date >= target_date
end
return nil unless target_date
target_date = Date.strptime(target_date)
year, month, day = *(date.split('-').map{|x| x.to_i})
year_jp = year - target_date.year + 1
ret = Date.new(year_jp, month, day)
if only_date
ret = ret.strftime(format)
else
gengou = @@_gengou[target_date]
year_jp = year_jp == 1 ? '元' : year_jp.to_s
ret = ret.strftime(format.gsub('%y', "#{gengou}#{year_jp}"))
end
ret
end
|