Module:Format time/sandbox
Appearance
| This is the module sandbox page for Module:Format time (diff). |
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| This module depends on the following other modules: |
This module is a fancy way to call {{#time}} in Lua. Unlike #time, it handles YMD dates (e.g. 2020 January 1) correctly via Module:YMD to ISO.
Syntax
[edit]From a template:
{{#invoke:Format date|main|<timestamp>|fmt=<Formatting string>}}
From a module:
require('Module:Format time')._main{<timestamp>, fmt = <Formatting string>}
In both cases, <timestamp> is any timestamp considered valid by {{#time}} plus YMD format. |fmt= can be any format according to mw:Help:Extension:ParserFunctions##time, and defaults to j xg Y, which renders dates like 28 June 2025.
local p = {}
function p.main(frame)
args = require('Module:Arguments').getArgs(frame)
return p._main{fmt = args['fmt'], s = args['s'] or args[1]}
end
function p._main(args)
-- args is a table with two values:
-- fmt = the format to output the time, according to [[:mw:Help:Extension:ParserFunctions##time]] (default: j xg Y)
-- s (or [1]) = the string to process; should be a date (default: empty string)
return mw.getContentLanguage():formatDate(args.fmt or 'j xg Y', require('Module:YMD to ISO')._main(args.s or args[1]), false)
end
return p