有兽档案馆
搜索
切换搜索
切换菜单
切换个人菜单
查看“Module:TimeAgo”的源代码
来自有兽档案馆
阅读
查看源代码
查看历史
模块
讨论
更多操作
←
Module:TimeAgo
因为以下原因,您没有权限编辑该页面:
您所请求的操作,仅限具有
注册用户
、
自动确认用户
、
管理员
、
界面管理员
、
优质编辑者
、
确认用户
、
巡查员
、
档案理事员
等
权限
的
用户
执行。
若您尚未登录有兽档案馆账号,请您
登录
有兽档案馆账号后操作。
本页目前被
模板保护
,只有
模板编辑员
才能进行编辑。
为何会出现这种情况?
部分
模板
由于其
高风险
及可见性会被
永久保护
。部分页面有时会因为
编辑争议
而受到保护。
关于本页被保护的理由、时间和类型,请参看
本页的保护日志
。如果未能在保护日志中查阅,本页可能是在保护之后被
移动
。
我现在可以做些什么?
您可以
和其他人讨论此页
。如果您无法编辑讨论页,请到
有兽茶谈
求助。
在讨论页提出一个编辑请求,让
模板编辑员
将您想要更改的内容提交上去。
若您想移动本页,请按照
页面重命名
的说明提出。
申请解除页面保护。
请注意提出请求时须附有合理原因,否则
模板编辑员
很可能会拒绝您的请求。
提出代为编辑请求
撰写草稿
提出解除页面保护
您尚未完成电子邮件确认,因此操作受限,请尽快
完成电子邮件确认
。
若您无法完成前述手续,请通过适当渠道请求管理员或档案理事员协助。
您可以查看和复制此页面的源代码。
若您无权编辑本页面,您可以
提出编辑请求
,提请有权限者代为编辑。
-- Replacement for [[Template:Time ago]] local numberSpell = require('Module:NumberSpell')._main local yesno = require('Module:Yesno') local p = {} -- Table to convert entered text values to numeric values. timeText = { ['seconds'] = 1, ['minutes'] = 60, ['hours'] = 3600, ['days'] = 86400, ['weeks'] = 604800, ['months'] = 2678400, ['years'] = 31557600 } -- Table containing tables of possible units to use in output. timeUnits = { [1] = { '秒', '秒', "秒", "秒" }, [60] = { '分钟', '分钟', "分钟", "分钟" }, [3600] = { '小时', '小时', "小时", "小时" }, [86400] = { '天', '天', "天", "天" }, [604800] = { '周', '周', "周", "周" }, [2678400] = { '个月', '个月', "个月", "个月" }, [31557600] = { '年', '年', "年", "年" } } function p._main( args ) -- Initialize variables local lang = mw.language.getContentLanguage() local auto_magnitude_num local min_magnitude_num local result local result_unit local magnitude = args.magnitude local min_magnitude = args.min_magnitude local purge = args.purge local spell_out = args.spellout local spell_out_max = args.spelloutmax -- Add a purge link if something (usually "yes") is entered into the purge parameter if purge then purge = '​<span class="plainlinks">([' .. mw.title.getCurrentTitle():fullUrl('action=purge') .. ' 更新])</span>' else purge = '' end -- Check that the entered timestamp is valid. If it isn't, then give an error message. local noError, inputTime = pcall( lang.formatDate, lang, 'U', args[1], true ) if not noError then return '<strong class="error">错误:第一个参数不能被解析为日期或时间。</strong>' end -- Store the difference between the current time and the inputted time, as well as its absolute value. local timeDiff = lang:formatDate( 'U', nil, true ) - inputTime local absTimeDiff = math.abs( timeDiff ) if magnitude then auto_magnitude_num = 0 min_magnitude_num = timeText[magnitude] else -- Calculate the appropriate unit of time if it was not specified as an argument. local autoMagnitudeData = { { denom = 63115200, amn = 31557600 }, { denom = 5356800, amn = 2678400 }, { denom = 172800, amn = 86400 }, { denom = 7200, amn = 3600 }, { denom = 120, amn = 60 } } for i, t in ipairs( autoMagnitudeData ) do if absTimeDiff / t.denom >= 1 then auto_magnitude_num = t.amn break end end auto_magnitude_num = auto_magnitude_num or 1 if min_magnitude then min_magnitude_num = timeText[min_magnitude] else min_magnitude_num = -1 end end if not min_magnitude_num then -- Default to seconds if an invalid magnitude is entered. min_magnitude_num = 1 end local magnitude_num = math.max( min_magnitude_num, auto_magnitude_num ) local result_num = math.floor ( absTimeDiff / magnitude_num ) local punctuation_key, suffix if timeDiff >= 0 then -- Past if result_num == 1 then punctuation_key = 1 else punctuation_key = 2 end if args.ago == '' then suffix = '' else suffix = '' .. (args.ago or '前') end else -- Future if args.ago == '' then suffix = '' if result_num == 1 then punctuation_key = 1 else punctuation_key = 2 end else suffix = '<!-- time-->' if result_num == 1 then punctuation_key = 3 else punctuation_key = 4 end end end result_unit = timeUnits[ magnitude_num ][ punctuation_key ] -- Convert numerals to words if appropriate. spell_out_max = tonumber( spell_out_max ) -- Would cause script errors if not a number. local result_num_text if ( spell_out == 'auto' and 1 <= result_num and result_num <= 9 and result_num <= ( spell_out_max or 9 ) ) or ( yesno( spell_out ) and 1 <= result_num and result_num <= 100 and result_num <= ( spell_out_max or 100 ) ) then result_num_text = numberSpell( result_num ) else result_num_text = tostring( result_num ) end result = result_num_text .. '' .. result_unit .. suffix -- Spaces for suffix have been added in earlier. return result .. purge end function p.main( frame ) local args = require( 'Module:Arguments' ).getArgs( frame, { valueFunc = function( k, v ) if v then v = v:match( '^%s*(.-)%s*$' ) -- Trim whitespace. if k == 'ago' or v ~= '' then return v end end return nil end, wrappers = 'Template:Time ago' }) return p._main( args ) end return p
该页面使用的模板:
Template:Documentation
(
查看源代码
)
Template:Tl
(
查看源代码
)
Module:Arguments
(
查看源代码
)
Module:Documentation
(
查看源代码
)
Module:Fullurl
(
查看源代码
)
Module:No globals
(
查看源代码
)
Module:NumberSpell
(
查看源代码
)
Module:Page name
(
查看源代码
)
Module:TimeAgo
(
查看源代码
)(模板编辑保护)
Module:TimeAgo/doc
(
查看源代码
)
Module:Tl
(
查看源代码
)
Module:Yesno
(
查看源代码
)
返回
Module:TimeAgo
。