モジュール:Date

提供:脳科学辞典
2014年4月20日 (日) 10:36時点におけるWikiSysop (トーク | 投稿記録)による版 (1版)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
ナビゲーションに移動 検索に移動

このモジュールについての説明文ページを モジュール:Date/doc に作成できます

--[[  
 
This module is intended for processing of date strings
 
]]
 
local date = {}

--[[
ISOyear
 
This function returns year part of date string.
 
Usage:
{{#invoke:Date|ISOyear|s=target_string}}
 
Parameters
    s: The date string 
 
If invoked using named parameters, Mediawiki will automatically remove any leading or
trailing whitespace from the target string.  
]]
function date.ISOyear( frame )
    local s = frame.args.s
    
    -- if empty string then return it
    if mw.ustring.len(s) == 0 then
        return s
    end
    
    -- if number then return it
    if tonumber( s ) then
        return mw.ustring.format('%04i', s)
    end
    
    -- otherwise use regular expression match
    s = mw.ustring.match( s, '(-?%d%d?%d?%d?)-' )
    if s then
       return mw.ustring.format('%04i', s)
    else
        return ''
    end
end

return date