コンテンツにスキップ

現在、全3219曲を聴きながらリンク集を作成中のサグラダ・ファミリア サイトです。
情報の誤りやお問い合わせは、管理人 X までお寄せください。
✨ オススメのプレイリストやセトリを教えて下さい ✨

Module:MemberStats

今日も推しが尊いですね。― ハロプロ・サブスク非公式リンク集
2026年2月20日 (金) 10:43時点におけるBarageki (トーク | 投稿記録)による版

local p = {}

-- 今日の日付をMediaWikiマジックワードで取得 local function getTodayYmd()

   local frame = mw.getCurrentFrame()
   local todayStr = frame:preprocess("2026041")  -- 例: 20260220
   return tonumber(todayStr)

end

function p.averageAge(frame)

   local args = frame.args
   local totalAge = 0
   local count = 0
   local today = getTodayYmd()   -- os.dateの代わり
   if not today then
       return "日付取得エラー"
   end
   for _, birthStr in ipairs(args) do
       local birth = tonumber(birthStr)
       if birth and birth >= 19000101 and birth <= today then
           -- 正確な年齢計算(誕生日が過ぎているかを考慮)
           local birthYear  = math.floor(birth / 10000)
           local birthMonth = math.floor((birth % 10000) / 100)
           local birthDay   = birth % 100
           local todayYear  = math.floor(today / 10000)
           local todayMonth = math.floor((today % 10000) / 100)
           local todayDay   = today % 100
           local age = todayYear - birthYear
           if todayMonth < birthMonth or (todayMonth == birthMonth and todayDay < birthDay) then
               age = age - 1
           end
           totalAge = totalAge + age
           count = count + 1
       end
   end
   if count == 0 then return "0" end
   local avg = totalAge / count
   return string.format("%.2f", avg)

end

function p.count(frame)

   local count = 0
   for _ in pairs(frame.args) do   -- ipairsではなくpairsで安全
       count = count + 1
   end
   return count

end

return p