光暦作成プログラムです。 ruby で作成いたしました。 csv形式(カンマ区切り)で出力いたします。
---- cal40.rb ---------------------------------------------
# -*- coding: utf-8 -*-
require 'date'
def cal40 date
ary = []
(1 .. 9).each {|mm|
max =
if mm.odd?
41
else
if mm == 2 and date.leap?
41
else
40
end
end
(1 .. max).each {|dd|
ary << [mm,dd]
}
}
ary
end
--- hikari.rb --------------------------------------------------------
def hikari n
a = n % 9
if a == 0
9
else
a
end
end
------ lightcal.rb -----------------------
# coding: utf-8
require './cal40'
require 'date'
require './hikari'
def lightcal year
date = Date.new(year,1,1)
ary = (cal40 date).map {|elm| hikari(elm[0]+elm[1])}
#year = 2018
dates = (Date.new(year, 1, 1)...Date.new(year + 1, 1, 1)).to_a
ary1 = dates.map {|d|
[d.month,d.day]
}
ary2 = ary1.zip(ary)
ary4 = []
(1 .. 31).each {|n|
h = {}
ary2.select {|elm| elm.first[1] == n}.each {|tmp|
h[tmp.first[0]] = tmp.last
}
ary5 = []
(1 .. 12).each {|m|
if h[m]
ary5 << h[m]
else
ary5 << "" #"-"
end
}
ary4 << ary5
}
ary4
end
nomal = lightcal 2018
leap = lightcal 2016
print "日\月,1,2,3,(3),4,5,6,7,8,9,10,11,12\n"
nomal.each_with_index {|elm,idx|
if idx == 28
elm[1] = leap[idx][1]
end
if idx < 22
elm.insert(3,leap[idx][2])
else
elm.insert(3,"")
end
print idx+1,",",elm.join(","),"\n"
}
----------------------------------------------------------------------
出力結果
日\月,1,2,3,(3),4,5,6,7,8,9,10,11,12
1,2,6,3,4,4,7,7,7,7,8,2,2,2
2,3,7,4,5,5,8,8,8,8,9,3,3,3
3,4,8,5,6,6,5,9,9,9,1,4,4,4
4,5,9,6,7,7,6,1,1,1,2,5,5,5
5,6,1,7,8,8,7,2,2,2,3,6,6,6
6,7,2,8,9,9,8,3,3,3,4,7,7,7
7,8,3,9,1,1,9,4,4,4,5,8,8,8
8,9,4,1,2,2,1,5,5,5,6,9,9,9
9,1,5,2,3,3,2,6,6,6,7,1,1,1
10,2,6,3,4,4,3,7,7,7,8,2,2,2
11,3,3,4,5,5,4,8,8,8,9,3,3,3
12,4,4,5,6,6,5,6,9,9,1,9,4,4
13,5,5,6,7,7,6,7,1,1,2,1,5,5
14,6,6,7,8,8,7,8,2,2,3,2,6,6
15,7,7,8,9,9,8,9,3,3,4,3,7,7
16,8,8,9,1,1,9,1,4,4,5,4,8,8
17,9,9,1,2,2,1,2,5,5,6,5,9,9
18,1,1,2,3,3,2,3,6,6,7,6,1,1
19,2,2,3,4,4,3,4,7,7,8,7,2,2
20,3,3,4,5,5,4,5,8,8,9,8,3,3
21,4,4,5,6,6,5,6,9,9,1,9,1,4
22,5,5,6,7,7,6,7,1,1,2,1,2,5
23,6,6,4,,8,7,8,7,2,3,2,3,6
24,7,7,5,,9,8,9,8,3,4,3,4,7
25,8,8,6,,1,9,1,9,4,5,4,5,8
26,9,9,7,,2,1,2,1,5,6,5,6,9
27,1,1,8,,3,2,3,2,6,7,6,7,1
28,2,2,9,,4,3,4,3,7,8,7,8,2
29,3,3,1,,5,4,5,4,8,9,8,9,3
30,4,,2,,6,5,6,5,9,1,9,1,4
31,5,,3,,,6,,6,1,,1,,5
セコメントをする