Jump to content
Toggle menu
  • 3 articles
  • 75 files
  • 7 users
  • 37.9K 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
use require('strict') instead of require('Module:No globals')
Fulfilling edit request by CalendulaAsteraceae. Thanks for helping!
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 299: Line 299:
   * 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 lang or not mw.language.isValidCode(lang) then
-- get user's chosen language
lang = mw.getCurrentFrame():callParserFunction("int", "lang")
if not lang or not mw.language.isValidCode(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 lang or not mw.language.isValidCode(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 405:


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


Line 410: Line 424:
]]
]]
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 'dtstart'
-- 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.