Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:DateI18n: Difference between revisions

From Neodyland Wiki
m allow "case=-" to mean the same as "case="
 
(2 intermediate revisions by 2 users not shown)
Line 8: Line 8:
This module is intended for processing of date strings.
This module is intended for processing of date strings.


Please do not modify this code without applying the changes first at Module:Date/sandbox and testing  
Please do not modify this code without applying the changes first at Module:DateI18n/sandbox
at Module:Date/sandbox/testcases and Module talk:Date/sandbox/testcases.
and testing at Module:DateI18n/sandbox/testcases and Module talk:DateI18n/sandbox/testcases.


Authors and maintainers:
Authors and maintainers:
* User:Parent5446 - original version of the function mimicking template:ISOdate
* User:Parent5446 - original version of the function mimicking Template:ISOdate
* User:Jarekt - original version of the functions mimicking template:Date  
* User:Jarekt - original version of the functions mimicking Template:Date  
]]
]]


Line 20: Line 20:
-- =======================================
-- =======================================


require('Module:No globals')
require('strict')


-- =======================================
-- =======================================
Line 277: Line 277:
end
end
return timeStamp, datecode
return timeStamp, datecode
end
local function isValidLangCode(lang)
if not lang then
return false
end
lang = mw.text.trim(lang)
return lang ~= '' and lang ~= '⧼Lang⧽' and mw.language.isValidCode(lang)
end
end


Line 299: Line 307:
   * class: CSS class for the <time> node, use "" for no metadata at all
   * class: CSS class for the <time> node, use "" for no metadata at all
]]
]]
function p._Date(datevec, lang, case, class, trim_year)
function p._Date(datevec, lang, case, class, trim_year)
-- make sure inputs are in the right format
-- make sure inputs are in the right format
if not lang or not mw.language.isValidCode( lang ) then
lang = mw.getCurrentFrame():callParserFunction( "int", "lang" ) -- get user's chosen language
-- set language
if not isValidLangCode(lang) then
-- get user's chosen language
-- equivalent to {{int:lang}}
lang = mw.getCurrentFrame():callParserFunction("int", "lang")
if not isValidLangCode(lang) then
-- if that doesn't work, use the project language
-- this is useful on projects which import this module from Commons
lang = mw.language.getContentLanguage().code
if not isValidLangCode(lang) then
-- if that doesn't work, use English
lang = "en"
end
end
end
end
if lang == 'be-tarask' then
if lang == 'be-tarask' then
Line 391: Line 414:


-- ===========================================================================
-- ===========================================================================
-- === Versions of the function to be called from template namespace
-- === Version of the function to be called from template namespace
-- ===========================================================================
-- ===========================================================================


Line 410: Line 433:
]]
]]
function p.Date(frame)
function p.Date(frame)
-- get args
local args = {}
local args = {}
for name, value in pairs( frame.args ) do  
for key, value in pairs(frame.args) do  
name = string.gsub( string.lower(name), ' ', '_')
local trimmed_key = string.gsub(string.lower(mw.text.trim(key)), ' ', '_')
args[name] = value
local trimmed_value = mw.text.trim(value)
if trimmed_key ~= 'class' and trimmed_value == '' then
trimmed_value = nil
end
args[trimmed_key] = trimmed_value
end
end
-- default values
-- Allows to set the html class of the time node where the date is included. This is useful for microformats.
args.class = args.class or '-'
if args.class == '' then
args.class = 'dtstart'
end
-- By default, pad one- and two-digit years to be 4 digits long, while keeping three-digit years as-is.
args.trim_year = args.trim_year or '100-999'
return p._Date(
return p._Date(
{ args.year, args.month, args.day, args.hour, args.minute, args.second, args.tzhour, args.tzmin },
{args.year, args.month, args.day, args.hour, args.minute, args.second, args.tzhour, args.tzmin},
args.lang,                 -- language
args.lang,
args.case,                 -- allows to specify grammatical case for the month for languages that use them
args.case,
args.class or 'dtstart',   -- allows to set the html class of the time node where the date is included. This is useful for microformats.
args.class,
args.trim_year or '100-999' -- by default pad one and 2 digit years to be 4 digit long, while keeping 3 digit years as is
args.trim_year
)
)
end
end


return p
return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.