https://femiwiki.com/index.php?title=%EB%AA%A8%EB%93%88:ISOdate&feed=atom&action=history모듈:ISOdate - 편집 역사2024-03-29T11:00:53Z이 문서의 편집 역사MediaWiki 1.41.0https://femiwiki.com/index.php?title=%EB%AA%A8%EB%93%88:ISOdate&diff=314546&oldid=prevLarodi: 판 1개를 가져왔습니다2023-06-21T07:34:38Z<p>판 1개를 가져왔습니다</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<tr class="diff-title" lang="ko">
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">← 이전 판</td>
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">2023년 6월 21일 (수) 16:34 판</td>
</tr><tr><td colspan="2" class="diff-notice" lang="ko"><div class="mw-diff-empty">(차이 없음)</div>
</td></tr></table>Larodihttps://femiwiki.com/index.php?title=%EB%AA%A8%EB%93%88:ISOdate&diff=314545&oldid=prevWikipedia>*Youngjin: 사용자가 "모듈:ISOdate" 문서를 보호했습니다: 훼손시 영향이 큰 틀 문서 ([편집=자동 인증된 사용자만 허용] (무기한) [옮기기=자동 인증된 사용자만 허용] (무기한))2015-03-16T00:05:57Z<p>사용자가 "<a href="/w/%EB%AA%A8%EB%93%88:ISOdate" class="fw-link" title="모듈:ISOdate">모듈:ISOdate</a>" 문서를 보호했습니다: 훼손시 영향이 큰 틀 문서 ([편집=자동 인증된 사용자만 허용] (무기한) [옮기기=자동 인증된 사용자만 허용] (무기한))</p>
<p><b>새 문서</b></p><div>--[[ <br />
<br />
This module is intended for processing of date strings.<br />
<br />
Please do not modify this code without applying the changes first at Module:ISOdate/sandbox and testing <br />
at Module:ISOdate/sandbox/testcases and Module talk:ISOdate/sandbox/testcases.<br />
<br />
Authors and maintainers:<br />
* User:Parent5446 - original version of the function mimicking template:ISOdate<br />
* User:Jarekt - original version of the functions mimicking template:Date and template:ISOyear<br />
<br />
]]<br />
<br />
<br />
local p = {}<br />
<br />
-- =======================================<br />
-- === Dependencies ======================<br />
-- =======================================<br />
local D = require('Module:Date2')<br />
<br />
--[[<br />
ISOyear<br />
<br />
This function returns year part of date string.<br />
<br />
Usage:<br />
{{#invoke:ISOdate|ISOyear|target_string}}<br />
<br />
Parameters<br />
1: The date string <br />
<br />
Error Handling:<br />
If the string does not look like it contain the year than the function will not return anything.<br />
That is the preferred treatment for the template:Creator which is the main (only?) template calling it.<br />
]]<br />
function p.ISOyear( frame )<br />
local input = frame.args[1]<br />
if not input then<br />
input = frame.args["s"]<br />
end<br />
input = mw.text.trim( input )<br />
<br />
-- if empty string then return it<br />
if input == "" then<br />
return input<br />
end<br />
<br />
-- if number then return it<br />
if tonumber( input ) then<br />
return mw.ustring.format( '%04i', input )<br />
end<br />
<br />
-- otherwise use regular expression match<br />
input = mw.ustring.match( input, '^(-?%d%d?%d?%d?)-' )<br />
if input then<br />
return mw.ustring.format( '%04i', input )<br />
else<br />
return ''<br />
end<br />
end<br />
<br />
--[[<br />
ISOdate<br />
<br />
This function is the core part of the ISOdate template. <br />
<br />
Usage:<br />
{{#invoke:ISOdate|ISOdate|target_string|lang=}}<br />
<br />
Parameters:<br />
1: The date string <br />
lang: The language to display it in<br />
form: Language format (genitive, etc.) for some languages<br />
class: CSS class for the <time> node<br />
<br />
Error Handling:<br />
If the string does not look like it contain the proper ISO date than the function will return the original string.<br />
<br />
That is the preferred treatment for the template:Information (and similar templates) which calling it.<br />
]]<br />
function p.ISOdate(frame)<br />
local datestr, succeded<br />
datestr, succeded = p._ISOdate(<br />
mw.text.trim(frame.args[1]),<br />
frame.args["lang"], -- language<br />
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 <br />
)<br />
return datestr<br />
end<br />
<br />
function p._ISOdate(datestr, lang, trim_year)<br />
<br />
-- pattern: regexp - regular expresion to test; dlen - number of date elements; tail = which element is a "tail" if any<br />
-- regexp hints:<br />
-- 1) Strings starting with "^" and ending with "$" indicate whole string match<br />
-- 2) optional tail part copied as-is and following the main parsed part of the date have to be separated from the date by a whitespace, so "(\s.+)?"<br />
local patterns = {<br />
-- strings starting with YYYY-MM-DD. Year 1-4 digits, the rest 1-2<br />
{dlen=3, tail=4, regexp="^(%d%d?%d?%d?)-(%d%d?)-(%d%d?)(%s.+)"},<br />
{dlen=3, tail=0, regexp="^(%d%d?%d?%d?)-(%d%d?)-(%d%d?)$"},<br />
-- strings starting with YYYY-MM. Year 3-4 digits, month 2 digits<br />
-- (want to avoit converting to dates strings like 10-5 = 5<br />
{dlen=2, tail=3, regexp="^(%d%d%d%d?)-(%d%d)(%s.+)"}, <br />
-- if whole string is in YYYY-MM form: If Year 1-4 digits, month 1-2 digits<br />
{dlen=2, tail=0, regexp="^(%d%d?%d?%d?)-(%d%d?)$"}, <br />
-- string starts with a number -> it has to be 3 or 4 digit long to be a year<br />
{dlen=1, tail=2, regexp="^(%d%d%d%d?)(%s.+)"}, <br />
-- if whole string is a number (1-4 digit long) than it will be interpreted as a year<br />
{dlen=1, tail=0, regexp="^(%d%d?%d?%d?)$"},<br />
}<br />
<br />
-- create datevec based on which variables are provided<br />
local datevec, tail, formatNum<br />
datevec, tail, formatNum = p.test_date_formats(datestr, patterns)<br />
if datevec[1]=='' or datevec[1]==nil then<br />
-- quickly return if datestr does not look like date (it could be a template)<br />
return datestr, false<br />
end<br />
<br />
-- call p._Date function to format date string<br />
local succeded, datestr2<br />
succeded, datestr2 = pcall( D._Date, datevec, lang, trim_year)<br />
if succeded and datestr2~='' then<br />
return mw.text.trim( datestr2 .. tail), true<br />
else -- in case of errors return the original string<br />
return datestr, false<br />
end <br />
end<br />
<br />
function p.ISOdate_extended(frame)<br />
-- pattern: regexp - regular expresion to test; dlen - number of date elements; tail = which element is a "tail" if any<br />
-- regexp hints:<br />
-- 1) Strings starting with "^" and ending with "$" indicate whole string match<br />
-- 2) optional tail part copied as-is and following the main parsed part of the date have to be separated from the date by a whitespace, so "(\s.+)?"<br />
<br />
local datestr, succeded<br />
datestr, succeded = p._ISOdate(<br />
mw.text.trim(frame.args[1]),<br />
frame.args["lang"], -- language<br />
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 <br />
)<br />
if succeded then<br />
return datestr<br />
end<br />
<br />
local datevec, tail, formatNum, category = ''<br />
datevec, tail, formatNum = p.test_date_formats(frame.args[1], patterns)<br />
if formatNum==1 or formatNum==2 then<br />
vec = datevec;<br />
if tonumber(datevec[1])>12 then<br />
frame.args[1] = string.format('%04i-%02i-%02i', datevec[3], datevec[2], datevec[1] )<br />
category = '[[Category:Date in DD/MM/YYYY format]]'<br />
return mw.text.trim( p.ISOdate(frame) .. tail);<br />
elseif tonumber(datevec[2])>12 then<br />
frame.args[1] = string.format('%04i-%02i-%02i', datevec[3], datevec[1], datevec[2] )<br />
category = '[[Category:Date in MM/DD/YYYY format]]'<br />
return mw.text.trim( p.ISOdate(frame) .. tail);<br />
end<br />
elseif (formatNum==3 or formatNum==4) and (datevec[3]=='' or datevec[3]~=nil) then<br />
local str = mw.getCurrentFrame():callParserFunction( "#time", { 'Y-m-d', datestr} )<br />
local vec = {str:match( "^(%d%d?%d?%d?)-(%d%d?)-(%d%d?)$" )}<br />
if vec and vec[1]~=nil then<br />
frame.args[1] = string.format('%04i-%02i-%02i', vec[1], vec[2], vec[3] )<br />
category = '[[Category:Date in word format]]'<br />
return p.ISOdate(frame);<br />
end<br />
end <br />
return datestr<br />
end<br />
<br />
function p.test_date_formats(datestr, patterns)<br />
-- pattern: regexp - regular expresion to test; dlen - number of date elements; tail = which element is a "tail" if any<br />
<br />
local datevec = {'','','','','',''}<br />
local tail = ''<br />
local vec, pat<br />
local formatNum = 0<br />
for i, pat in ipairs( patterns ) do<br />
vec = {datestr:match( pat.regexp )}<br />
if vec and vec[1]~=nil then<br />
for j=1,pat.dlen do<br />
datevec[j] = vec[j]<br />
end<br />
if pat.tail>0 and vec[pat.tail]~=nil then<br />
tail = mw.ustring.gsub(' ' .. vec[pat.tail], ' +', ' ')<br />
end<br />
formatNum = i<br />
break<br />
end<br />
end<br />
return datevec, tail, formatNum<br />
end<br />
<br />
return p</div>Wikipedia>*Youngjin