Moduł:Wikidane/format/prolepticGregorianCalendar
< Moduł:Wikidane | format
Przejdź do nawigacji
Przejdź do wyszukiwania
Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Wikidane/format/prolepticGregorianCalendar/opis
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 = - 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) local formatted = mw.getContentLanguage():formatDate(format,timestamp) -- return left-trimmed year (e.g. 0013 p.n.e -> 13 p.n.e) return formatted:gsub("%f[0-9+%-]0(%d%d%d)%f[^0-9]", function (s) return s:match("^0*(%d+)$") end) end, }