跳转到内容
打开/关闭搜索
搜索
打开/关闭菜单
397
文件
1978
用户
1.2万
编辑
Gal中文百科
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
在其他项目中
打开/关闭外观设置菜单
无法加载偏好设置。请检查您的网络连接并重试。
重试
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
user-interface-preferences
个人工具
讨论
贡献
创建账号
登录
编辑“︁
Module
:
Date Convert
”︁
来自Gal中文百科
查看
阅读
编辑源代码
查看历史
associated-pages
模块
讨论
更多操作
更多
工具
链入页面
相关更改
页面信息
警告:
您没有登录。如果您进行任何编辑,您的IP地址会公开展示。如果您
登录
或
创建账号
,您的编辑会以您的用户名署名,此外还有其他益处。
反垃圾检查。
不要
加入这个!
require('strict') local getArgs = require('Module:Arguments').getArgs local yesno = require('Module:Yesno') local p = {} local function error(template) return '<strong class="error">错误:时间格式不正确</strong>[[Category:Template:' .. template .. '使用错误]]' end local function time(format, object) return mw.getCurrentFrame():callParserFunction('#time', format, object) end local function convert(input) input = input :gsub(" "," ") :gsub("%s+"," ") :gsub('(%a+)[ ,]*(%d+)', '%1 %2'); local y, m, d, suf local datePatternList = { -- English date format {'%d%d? ?%a+[ ,]*%d+', 'Y-m-d'}, -- 26 Oct 1994 {'%a+ ?%d%d?[ ,]+%d+', 'Y-m-d'}, -- Oct 26, 1994 {'%a+[ ,]*%d%d%d%d+', 'Y-m'}, -- Oct 1994 {'%a+ ?%d%d?', 'Y-m-d'}, -- Oct 26 {'%d%d? *%a+', 'Y-m-d'}, -- 26 Oct -- Slash or hyphen date format {'%d+/%d%d?/%d+', 'Y-m-d'}, -- 1994/10/26 or 10/26/1994 {'%d+%.%d%d?%.%d+', 'Y-m-d'}, -- 1994.10.26 or 26.10.1994 {'%d%d?/%d%d?', 'Y-m-d'}, -- 10/26 {'%d+%-%d%d?%-%d+', 'Y-m-d'}, -- 1994-10-26 or 26-10-94 {'%d%d%d%d+%-%d%d?', 'Y-m'}, -- 1994-10 {'%d%d%d%d', 'Y'}, -- 1994 } y, m, d, suf = string.match(input, '^(%d+)年(%d%d?)月(%d%d?)日(.*)$'); if y then if #y < 4 then y = string.rep(0, 4 - #y) .. y end return time('Y-m-d', y .. '-' .. m .. '-' .. d) , suf end y, m, suf = string.match(input, '^(%d+)年(%d%d?)月(.*)$'); if y then if #y < 4 then y = string.rep(0, 4 - #y) .. y end return time('Y-m', y .. '-' .. m) , suf end y, suf = string.match(input, '^(%d+)年(.*)$'); if y then if #y < 4 then y = string.rep(0, 4 - #y) .. y end return time('Y', y) , suf end m, d, suf = string.match(input, '^(%d%d?)月(%d%d?)日(.*)$'); if m and tonumber(m) then return time('m-d', m .. '-' .. d) , suf end for _, value in ipairs(datePatternList) do local str, suf = string.match(input, '^(' .. value[1] .. ')(.*)$'); if str then return time(value[2], str), suf end end return time('Y-m-d', 'error') end function p._converttime(input, showsuf) local date, suf = convert(input) if (yesno(showsuf)) then return date .. suf else return date end end function p._ChineseDate(args, error) local date, suffix = convert(args[1]) local errorMessage = time('Y-m-d', 'error') suffix = args.suf and suffix or '' if string.match(date, '^%d+%-%d%d%-%d%d$') then return time('Y年Fj日', date):gsub("^0+","") .. suffix end if string.match(date, '^%d+%-%d%d$') then return time('Y年F', date):gsub("^0+","") .. suffix end if string.match(date, '^%d+$') then return time('Y年', date):gsub("^0+","") .. suffix end if string.match(date, '^%d%d%-%d%d$') then return time('Fj日', date):gsub("^0+","") .. suffix end if date == errorMessage and args.error == 'ignore' then return args[1] end --- return error('Chinese_date') return '<strong class="error">错误:时间格式不正确</strong>[[Category:Template:Chinese_date使用错误]]' end function p.ChineseDate(frame) local args = getArgs(frame) return p._ChineseDate(args) end function p._ISODate(args, error) local returnval, suf = convert(args[1]) local errorMessage = time('Y-m-d', 'error') if returnval == errorMessage and args.error == 'ignore' then return args[1] end if returnval == errorMessage then --- return error('ISODate') return '<strong class="error">错误:时间格式不正确</strong>[[Category:Template:ISODate使用错误]]' end return returnval .. (args.suffix and suf or '') end function p.ISODate(frame) local args = getArgs(frame) return p._ISODate(args) end return p
摘要:
请注意,所有对Gal中文百科的贡献均可能会被其他贡献者编辑、修改或删除。如果您不希望您的文字作品被随意编辑,请不要在此提交。
您同时也向我们承诺,您提交的内容为您自己所创作,或是复制自公共领域或类似自由来源(详情请见
Gal中文百科:著作权
)。
未经许可,请勿提交受著作权保护的作品!
取消
编辑帮助
(在新窗口中打开)
此页面嵌入的页面:
Module:Date Convert/doc
(
编辑
)
编辑“︁
Module
:
Date Convert
”︁
来自Gal中文百科