Module:DateTime

From Puella Magi Wiki
Jump to navigation Jump to search
Module Documentation    [edit]

A utility module for dealing with datetime.

Usage

format

Format the datetime. Either only date:

{{#invoke:DateTime|format|2026-09-10}}
2026-09-10

or date with time:

{{#invoke:DateTime|format|2026-09-10T14:00:00}}
2026-09-10 14:00:00

or date with time and timezone:

{{#invoke:DateTime|format|2026-09-10T14:00:00+0900}}
2026-09-10 05:00:00

local getArgs = require('Module:Arguments').getArgs
local p = {}

function p.format(frame)
    local args = getArgs(frame)
    local dt = args[1] or ""
    if dt == "" then
        return ""
    end

	local fmt = "Y-m-d"
    if string.find(dt, "T") or string.find(dt, ":") then
    	fmt ="Y-m-d H:i:s"
    end

    local success, result = pcall(function()
        return mw.getContentLanguage():formatDate(fmt, dt)
    end)

    if success then
    	return result
    end

	return dt
end

return p