Przejdź do zawartości

Moduł:Wikidane/format/prolepticGregorianCalendar

Z Wikibooks, biblioteki wolnych podręczników.
 Dokumentacja modułu [zobacz] [edytuj] [historia] [odśwież]

Dedykowana uniwersalna wtyczka formatująca wartość cechy z czasem (zwykle datą) w kalendarzu gregoriańskim.

Wtyczka obsługuje parametr linkuj.

Zobacz też

local moduleData = mw.loadData("Module:Wikidane/data")
 
return {
 
scope = "snak",
 
format = function(snak, options)
	local value = snak.datavalue.value
	local timeFormats = (options.linkDate and moduleData.linkTimeFormats or moduleData.plainTimeFormats)[value.precision]
	if not timeFormats then
		mw.log(string.format(moduleData.warnNotSupportedPrecision, value.precision))
		return nil
	end
 
	if (value.before ~= 0) or (value.after ~= 0) then
		mw.log(string.format(moduleData.warnNotSupportedTimeArgs, value.before, value.after))
		-- I do not understand this values yet
		return nil
	end
 
	local sign_year, month, day, hour, minute, second = string.match(value.time, "^([+-]%d%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?)-(%d%d)-(%d%d)T(%d%d):(%d%d):(%d%d)Z$", 1)
	if not sign_year or not month or not day or not hour or not minute or not second then
		mw.log(string.format(moduleData.warnUnrecognizedTime, value.time))
		return nil
	end
 
	local year = tonumber(sign_year)
	local format = timeFormats[1]
	if year <= 0 then
		year = 1 - year
		format = timeFormats[2]
	end
 
	assert(format)
	assert(year >= 1)
	if year > 9999 then
		mw.log(string.format(moduleData.warnYearOutOfRange, sign_year))
		return nil
	end
 
	local timezone = value.timezone
	local offset = ""
	if timezone < -1 then
		offset = string.format(" %d minutes", timezone)
	elseif timezone == -1 then
		offset = " -1 minute"
	elseif timezone == 1 then
		offset = " +1 minute"
	elseif timezone > 1 then
		offset = string.format(" +%d minutes", timezone)
	end
 
 	if month == "00" then
 		month = "01"
 	end
 	if day == "00" then
 		day = "01"
 	end
 	
	local timestamp = string.format("%04d%s%s %s%s%s%s", year, month, day, hour, minute, second, offset)
	return mw.getContentLanguage():formatDate(format,timestamp)
end,
 
}