Module:Date complexe
Révision datée du 27 septembre 2014 à 16:14 par Zolo (discussion) (Nouvelle page : -- Translates and format date range sand other non punctual dates --inspired by Commons:Module:Other dates local datemodule = require('Module:Date') local p = {} --[[ wikibase...)
La documentation pour ce module peut être créée à Module:Date complexe/doc
-- Translates and format date range sand other non punctual dates --inspired by [[Commons:Module:Other dates]] local datemodule = require('Module:Date') local p = {} --[[ wikibase format precision = 0: 1 Gigayear 1: 100 Megayears 2: 10 Megayears 3: Megayear 4: 100 Kiloyears 5: 10 Kiloyears 6: Kiloyear 7: 100 years 8: 10 years 9: years 10: months 11: days 12: hours 13: minutes 14: seconds ]]-- local function totext(obj, lang, case) return datemodule.Wikibasedate(obj, lang, case) end local function from(startpoint, lang) local precision = tonumber(startpoint.precision) local value = function() if precision > 10 then -- precision > month return "à partir du " .. totext(startpoint, lang) else return "à partir de " .. totext(startpoint, lang) end end return value() end local function fromuntil(startpoint, endpoint, lang) local precision = tonumber(startpoint.precision) -- may need 2 precisions for start and end local value = function() -- could actually be better should be "d'octobre à mars 2013' not "de octore 2013 à mars 2013" if precision > 10 then -- precision > month return "du " .. totext(startpoint, lang) .. " au " .. totext(endpoint, lang) else -- "DE septebmbre" / "D'octobre" return require('Module:Linguistic').of(totext(startpoint, 'fr'), 'fr') .. " à " .. totext(endpoint, lang) end end return value() end local function upto(endpoint, lang) local precision = tonumber(endpoint.precision) -- may need 2 precisions for start and end local value = function() if precision > 10 then -- precision > month return "jusqu'au " .. totext(endpoint, lang) else return "jusqu'à " .. totext(endpoint, lang) end end return value() end function p.wikibasedaterange(timedata, lang, case) local startpoint, endpoint, timepoint = timedata.startpoint, timedata.endpoint, timedata.timepoint if startpoint and endpoint then return fromuntil(startpoint, endpoint, lang) end if startpoint then return from(startpoint, lang) end if endpoint then return upto(endpoint, lang) end if timepoint then return datemodule.Wikibasedate(timepoint, lang) end end function p.compactdaterange(timedata, lang) -- YXXX-YXXX format local startyear, endyear = '', '' if timedata.startpoint then startyear = string.sub(timedata.startpoint.time, 9, 12) end if timedata.endpoint then endyear = string.sub(timedata.endpoint.time, 9, 12) end -- remove leading zeros while string.sub(startyear, 1,1) == '0' do startyear = string.sub(startyear, 2) end while string.sub(endyear, 1,1) == '0' do endyear = string.sub(endyear, 2) end return startyear .. '-' .. endyear end return p