Modul:Wikidata/Formatters/frequency

Z Wikipedie, otevřené encyklopedie

Dokumentaci tohoto modulu lze vytvořit na stránce Modul:Wikidata/Formatters/frequency/Dokumentace

require 'Modul:No globals'

local p = {}

local parent = require 'Modul:Wikidata/Formatters/quantity'

p.getRawValue = parent.getRawValue

local function isPositiveInteger(value)
	if value > 0 then
		local int, fract = math.modf(value)
		if int == value then
			return true
		end
	end
	return false
end

local function formatNumber(value, options)
	-- todo: 0.5 days -> twice a day
	if isPositiveInteger(value) then
		if value == 1 then
			return 'každý'
		else
			return mw.ustring.format('každý %d.', value)
		end
	else
		return parent.formatNumber(value, options)
	end
end

local function formatUnit(entityId)
	local Formatters = require 'Modul:Wikidata/Formatters'
	return Formatters.formatRawValue(entityId, 'wikibase-entityid', { nolink = true }) -- unset label = 'unitsymbol'
end

p.formatRawValue = p.formatNumber

function p.formatValue(value, options)
	parent.setFormatNumber(formatNumber)
	parent.setFormatUnit(formatUnit)
	return parent._formatValue(value, options)
end

return p