モジュール:Date
ナビゲーションに移動
検索に移動
local p = {}
local function ymd2mjd(y, m, d)
return require('Module:MJD').ymd2mjd({y, m, d})
end
local function mjd2ymd(mjd)
return require('Module:MJD').mjd2ymd({mjd})
end
function p.main(frame)
local args
if type(frame.args) == 'table' then
args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:Date', removeBlanks = false})
else
args = frame
end
local format = args.format or ''
local y, m, d, mjd
if args.mjd ~= nil then
mjd = args.mjd
local ymd = mjd2ymd(mjd)
y = ymd[1]
m = ymd[2]
d = ymd[3]
elseif args[1] ~= nil then
date = args[1]
local pattern = {'(%d+)年(%d+)月(%d+)日', '(%d*)-(%d*)-(%d*)', '(%d%d%d%d)(%d%d)(%d%d)'}
for i = 1, #pattern do
y, m, d = string.match(date, pattern[i])
if y then break end
end
mjd = ymd2mjd(y, m, d)
else
local curymd = require('Module:MJD').curymd()
y = tonumber(args['年']) or curymd[1]
m = tonumber(args['月']) or curymd[2]
d = tonumber(args['日']) or curymd[3]
mjd = ymd2mjd(y, m, d)
end
local pattern = {
y = tonumber(y),
m = tonumber(m),
d = tonumber(d),
yy = string.format('%02d', math.mod(y, 100)),
yyyy = string.format('%04d', y),
mm = string.format('%02d', m),
dd = string.format('%02d', d),
aaa = ({'日', '月', '火', '水', '木', '金', '土'})[(mjd - 4) % 7 + 1],
}
text = string.gsub(format, '<(.-)>', pattern)
return text
end
return p