Module:Get article date format
| This module is rated as beta. It is considered ready for widespread use, but as it is still relatively new, it should be applied with some caution to ensure results are as expected. |
| This module depends on the following other modules: |
| This module is required by Module:Format work |
Usage
Provide an article title as the value of |page= to get its explicit or implicit date format.
- explicit:
F j, Yif {{use mdy dates}}, orj F Yif {{use dmy dates}} is in use - implicit:
F j, Yif {{use American English}} is in use, orj F Y(used everywhere else globally)
{{#invoke:Get article date format|main
| page = Example
}}
Returns: j F Y
Alarming messages
If a supplied |page= is not valid (has no content (includes not existing)), the return will be the default j F Y.
The implicitly invoked Module:Find templates in use will display a preview warning if there is no active content, but the return will be the default.
-- TODO allow influence of the form of the output?
local DMY = 'j F Y'
local MDY = 'F j, Y'
local _getTemplates = require('Module:Find templates in use').main
local function _isEmpty(value) return value == nil or value == '' end
local function _alarmingMessage(message)
return '<span class="error">[[Module:Get article date format]] '..message..'.</span>'
-- TODO ..'[[Category:Pages displaying alarming messages about Module:Get article date format]]'
end
local function _implicitDateFormat(page_name)
-- Of all our currently templated engvars, only the US uses mdy exclusively.
local templates = _getTemplates({
page = page_name,
templates = table.concat({
'Use American English',
-- Redirects:
'Use US English',
'Use U.S. English',
'EngvarA',
'En-US',
'Use United States English',
'Use american English',
'Use american english',
'En-us',
'Enus',
'US-en',
'Use USA English',
'Use American',
'Use American ENGLISH',
'Use Mexican American English',
'Use American spelling'
}, '#')
})
if type(templates) ~= 'table' then
mw.addWarning(templates)
return nil
end
for k, v in pairs(templates) do
return MDY
end
return DMY
end
local function _explicitDateFormat(page_name)
local title_table = mw.title.new(page_name)
if _isEmpty(title_table) or not title_table:inNamespace(0) then
return DMY
end
local templates = _getTemplates({
page = page_name,
templates = table.concat({
'Use mdy dates',
-- Redirects:
'Mdy',
'MDY',
'Use MDY dates',
'Usemdy',
'Usemdydates',
'Use MDY',
'Use mdy',
'Use mdy date',
'Use dmy dates',
-- Redirects:
'Dmy',
'DMY',
'Use DMY dates',
'Usedmy',
'Use dmy',
'Use DMY',
'Usedmydates'
}, '#')
})
if type(templates) ~= 'table' then
mw.addWarning(templates)
return nil
end
local date_format = nil
for k, v in pairs(templates) do
-- TODO handle multiples and conflicts
date_format = mw.ustring.match(k, '[Dd][Mm][Yy]')
if date_format then
return DMY
end
date_format = mw.ustring.match(k, '[Mm][Dd][Yy]')
if date_format then
return MDY
end
end
return date_format
end
local p = {}
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame)
if _isEmpty(args) then
return _alarmingMessage('could not getArgs') -- This really would be alarming.
end
local page_name = args.page or ''
return _explicitDateFormat(page_name) or _implicitDateFormat(page_name)
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.