差分

ナビゲーションに移動 検索に移動
1版 をインポートしました
1行目: 1行目:  
--[[   
 
--[[   
   
+
  __ __          _      _        ___ ____  ___      _      _     
 +
|  \/  | ___  __| |_  _| | ___ _|_ _/ ___| / _ \  __| | __ _| |_ ___
 +
| |\/| |/ _ \ / _` | | | | |/ _ (_)| |\___ \| | | |/ _` |/ _` | __/ _ \
 +
| |  | | (_) | (_| | |_| | |  __/_ | | ___) | |_| | (_| | (_| | ||  __/
 +
|_|  |_|\___/ \__,_|\__,_|_|\___(_)___|____/ \___/ \__,_|\__,_|\__\___|
 +
   
 
This module is intended for processing of date strings.
 
This module is intended for processing of date strings.
   9行目: 14行目:  
* 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 and template:ISOyear
 
* User:Jarekt - original version of the functions mimicking template:Date and template:ISOyear
   
]]
 
]]
   18行目: 22行目:  
-- === Dependencies ======================
 
-- === Dependencies ======================
 
-- =======================================
 
-- =======================================
local D = require('Module:Date')
+
local D = require('Module:DateI18n')
    
--[[
 
--[[
36行目: 40行目:  
]]
 
]]
 
function p.ISOyear( frame )
 
function p.ISOyear( frame )
local input = frame.args[1]
+
return p._ISOyear( frame.args[1] )
 +
end
 +
 
 +
function p._ISOyear( input )
 
if not input then
 
if not input then
input = frame.args["s"]
+
return ''
 
end
 
end
 
input = mw.text.trim( input )
 
input = mw.text.trim( input )
53行目: 60行目:  
      
 
      
 
-- otherwise use regular expression match
 
-- otherwise use regular expression match
input = mw.ustring.match( input, '^(-?%d%d?%d?%d?)-' )
+
input = mw.ustring.match( input, '^+?(-?%d%d?%d?%d?)-' )
if input then
+
if input and tonumber( input ) then
 
return mw.ustring.format( '%04i', input )
 
return mw.ustring.format( '%04i', input )
 
else
 
else
82行目: 89行目:  
function p.ISOdate(frame)
 
function p.ISOdate(frame)
 
local datestr, succeded
 
local datestr, succeded
 +
local args = frame.args
 +
if not (args.lang and mw.language.isSupportedLanguage(args.lang)) then
 +
args.lang = frame:callParserFunction( "int", "lang" ) -- get user's chosen language
 +
end
 
datestr, succeded = p._ISOdate(
 
datestr, succeded = p._ISOdate(
mw.text.trim(frame.args[1]),
+
mw.text.trim(args[1]),
frame.args["lang"],                  -- language
+
args.lang,                  -- language
frame.args["case"] or '',          -- allows to specify grammatical case for the month for languages that use them
+
args.case  or '',          -- allows to specify grammatical case for the month for languages that use them
frame.args["class"] or 'dtstart',    -- allows to set the html class of the time node where the date is included.  
+
args.class or 'dtstart',    -- allows to set the html class of the time node where the date is included.  
frame.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 or '100-999' -- by default pad one and 2 digit years to be 4 digit long, while keeping 3 digit years as is
 
)
 
)
 
return datestr
 
return datestr
101行目: 112行目:  
-- strings starting with YYYY-MM-DD HH:MM:SS. Year 4 digits (if we know seconds than it was within the last 100 years), the rest 1-2
 
-- strings starting with YYYY-MM-DD HH:MM:SS. Year 4 digits (if we know seconds than it was within the last 100 years), the rest 1-2
 
-- date and time can be separated by space or "T" and there could be a "Z" on the end indicating "Zulu" time zone
 
-- date and time can be separated by space or "T" and there could be a "Z" on the end indicating "Zulu" time zone
{dlen=6, tail=7, regexp="^(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?):(%d%d?)Z?(%s.*)"},  
+
{dlen=6, tail=7, regexp="^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?):(%d%d?)Z?(%s.*)"},  
{dlen=6, tail=0, regexp="^(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?):(%d%d?)Z?$"},  
+
{dlen=6, tail=0, regexp="^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?):(%d%d?)Z?$"},  
 
-- strings starting with YYYY-MM-DD HH:MM. Year 4 digits, the rest 1-2
 
-- strings starting with YYYY-MM-DD HH:MM. Year 4 digits, the rest 1-2
 
-- (if one knows hour and minute than it was probably after a year 1000)
 
-- (if one knows hour and minute than it was probably after a year 1000)
{dlen=5, tail=6, regexp="^(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?)(%s.+)"},
+
{dlen=5, tail=6, regexp="^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?)(%s.+)"},
{dlen=5, tail=0, regexp="^(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?)$"},
+
{dlen=5, tail=0, regexp="^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?)$"},
 
-- strings starting with YYYY-MM-DD. Year 1-4 digits, the rest 1-2
 
-- strings starting with YYYY-MM-DD. Year 1-4 digits, the rest 1-2
{dlen=3, tail=4, regexp="^(%d%d?%d?%d?)-(%d%d?)-(%d%d?)(%s.+)"},
+
{dlen=3, tail=4, regexp="^+?(%d%d?%d?%d?)-(%d%d?)-(%d%d?)(%s.+)"},
{dlen=3, tail=0, regexp="^(%d%d?%d?%d?)-(%d%d?)-(%d%d?)$"},
+
{dlen=3, tail=0, regexp="^+?(%d%d?%d?%d?)-(%d%d?)-(%d%d?)$"},
 
-- strings starting with YYYY-MM. Year 3-4 digits, month 2 digits
 
-- strings starting with YYYY-MM. Year 3-4 digits, month 2 digits
 
-- (want to avoit converting to dates strings like 10-5 = 5
 
-- (want to avoit converting to dates strings like 10-5 = 5
{dlen=2, tail=3, regexp="^(%d%d%d%d?)-(%d%d)(%s.+)"},  
+
{dlen=2, tail=3, regexp="^+?(%d%d%d%d?)-(%d%d)(%s.+)"},  
 
-- if whole string is in YYYY-MM form: If Year 1-4 digits, month 1-2 digits
 
-- if whole string is in YYYY-MM form: If Year 1-4 digits, month 1-2 digits
{dlen=2, tail=0, regexp="^(%d%d?%d?%d?)-(%d%d?)$"},  
+
{dlen=2, tail=0, regexp="^+?(%d%d?%d?%d?)-(%d%d?)$"},  
 
-- string starts with a number -> it has to be 3 or 4 digit long to be a year
 
-- string starts with a number -> it has to be 3 or 4 digit long to be a year
{dlen=1, tail=2, regexp="^(%d%d%d%d?)(%s.+)"},
+
{dlen=1, tail=2, regexp="^+?(%d%d%d%d?)(%s.+)"},
 
-- if whole string is a number (1-4 digit long) than it will be interpreted as a year
 
-- if whole string is a number (1-4 digit long) than it will be interpreted as a year
{dlen=1, tail=0, regexp="^(%d%d?%d?%d?)$"},
+
{dlen=1, tail=0, regexp="^+?(%d%d?%d?%d?)$"},
 
}
 
}
 
 
 
-- create datevec based on which variables are provided
 
-- create datevec based on which variables are provided
 
local datevec, tail, formatNum
 
local datevec, tail, formatNum
datevec, tail, formatNum = p.test_date_formats(datestr, patterns)
+
datevec, tail, formatNum = p.test_date_formats(datestr or '', patterns)
 
if datevec[1]=='' or datevec[1]==nil then
 
if datevec[1]=='' or datevec[1]==nil then
 
-- quickly return if datestr does not look like date (it could be a template)
 
-- quickly return if datestr does not look like date (it could be a template)
146行目: 157行目:     
local datestr, succeded
 
local datestr, succeded
 +
local args = frame.args
 +
if not (args.lang and mw.language.isSupportedLanguage(args.lang)) then
 +
args.lang = frame:callParserFunction( "int", "lang" ) -- get user's chosen language
 +
end
 
datestr, succeded = p._ISOdate(
 
datestr, succeded = p._ISOdate(
mw.text.trim(frame.args[1]),
+
mw.text.trim(args[1]),
frame.args["lang"],                  -- language
+
args.lang,                  -- language
frame.args["case"] or '',          -- allows to specify grammatical case for the month for languages that use them
+
args.case  or '',          -- allows to specify grammatical case for the month for languages that use them
frame.args["class"] or 'dtstart',    -- allows to set the html class of the time node where the date is included.  
+
args.class or 'dtstart',    -- allows to set the html class of the time node where the date is included.  
frame.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 or '100-999' -- by default pad one and 2 digit years to be 4 digit long, while keeping 3 digit years as is
 
)
 
)
 
if succeded then
 
if succeded then

案内メニュー