Bước tới nội dung

Mô đun:Archives/bots

Bách khoa toàn thư mở Wikipedia
local p = {}-- reproduced from Module:Convertlocal scale = {	second = 1,	seconds = 1,	["giây"] = 1,	minute = 60,	minutes = 60,	["phút"] = 60,	hour = 3600,	hours = 3600,	["giờ"] = 3600,	day = 86400,	days = 86400,	["ngày"] = 86400,	month = 2629800,	months = 2629800,	["tháng"] = 2629800,	year = 31557600,	years = 31557600,	["năm"] = 31557600}function p._human_readable_duration(args)	local time = tonumber(args[1])	if time == nil or time < 0 then		return		"<strong class='error'>Human readable duration error: First argument must be a positive number ([[Template:Human readable duration|help]])</strong>"	end	local unit = string.lower(args[2] or "")	if scale[unit] == nil then		return		"<strong class='error'>Human readable duration error: Second argument must be a valid time unit ([[Template:Human readable duration|help]])</strong>"	end	local timeseconds = time * scale[unit]	if timeseconds < 59.75 then -- rounds to 59.5 seconds or less		local converted = math.floor(timeseconds * 2 + 0.5) / 2		return converted .. " giây" .. (converted ~= 1 and "" or "")	elseif timeseconds < 3585 then -- rounds to 59.5 minutes or less		local converted = math.floor(timeseconds / scale.minute * 2 + 0.5) / 2		return converted .. " phút" .. (converted ~= 1 and "" or "")	elseif timeseconds < 258300 and timeseconds ~= 86400 and timeseconds ~= 172800 then -- rounds to 71.5 hours or less, excluding 24 and 48 hours exactly		local converted = math.floor(timeseconds / scale.hour * 2 + 0.5) / 2		return converted .. " giờ" .. (converted ~= 1 and "" or "")	elseif timeseconds < 4341600 then -- rounds to 50 days or less		local converted = math.floor(timeseconds / scale.day * 2 + 0.5) / 2		return converted .. " ngày" .. (converted ~= 1 and "" or "")	elseif timeseconds < 48651300 then -- rounds to 18 months or less (rounds to nearest integer instead of 0.5)		local converted = math.floor(timeseconds / scale.month + 0.5)		return converted .. " tháng" .. (converted ~= 1 and "" or "")	else -- anything over 18 months rounds to nearest 0.5 years		local converted = math.floor(timeseconds / scale.year * 2 + 0.5) / 2		return converted .. " năm" .. (converted ~= 1 and "" or "")	end	endfunction p.human_readable_duration(frame)	local args = frame:getParent().args	return p._human_readable_duration(args)endreturn p