« Module:Date complexe » : différence entre les versions

Contenu supprimé Contenu ajouté
Zolo (discuter | contributions)
debug
Zolo (discuter | contributions)
ajout d'une fonction "comparedate", et différencie "à partir de" de "depuis"
Ligne 120 :
end
 
local function fromdatefromToUnknown(d, displayformat) -- retourneretourn "à partir de" plutôt que date"depuis", quand on ne sait pas ensi langagec'est naturelterminé
if (precision >= 11) or (precision == 7) or (precision == 6) then -- ont dit "à partir du pour les dates avec jour, les siècles, les millénaires
return 'à partir du ' .. datestrd
end
if (precision == 10) and (vowelfirst(datemodule.nomDuMois(d.month))) then
return "à partir d'" .. datestrd
end
return 'à partir de ' .. d
end
 
local function fromdate(d, displayformat, finished) -- retourne "à partir de date" en langage naturel
displayformat = displayformat or {}
local precision = setprecision(d, displayformat.precision)
Ligne 126 ⟶ 136 :
if displayformat and displayformat.textformat == 'minimum' then
return datestr -- par exemple pour les classements MH, juste afficher la date de début
end
if finished then return
fromToUnknown(d)
end
if (precision >= 11) or (precision == 7) or (precision == 6) then -- ont dit "à partir du pour les dates avec jour, les siècles, les millénaires
if voweverlfirst(datestr) then -- suppose l'absence de lien interne
return 'à partir du ' .. datestr
return "depuis l'" .. datestr
else
--if vowelfirst(datestr) then
if (precision == 10) and (vowelfirst(datemodule.nomDuMois(d.month))) then
return "à partir d'" .. datestr
else
return "depuis partir de 'le" .. datestr
end
end
return "depuis " .. datestr
end
 
Ligne 222 ⟶ 233 :
end
 
function p.daterange(startpoint, endpoint, displayformat, finished)
if startpoint and endpoint then
return fromuntil(startpoint, endpoint, displayformat)
elseif startpoint then
return fromdate(startpoint, displayformat, finished) -- finished: booléen permettant de différencier entre "depuis" et "à partir de"
elseif endpoint then
return upto(endpoint, displayformat)
Ligne 240 ⟶ 251 :
return datemodule.age(start.year, start.month, start.day, ending.year, ending.month, ending.day)
end
 
function p.splitWDdate(d)
local pattern = "(%W)(%d+)%-(%d+)%-(%d+)"
local era, year, month, day = d:match(pattern)
year, month, day = tonumber(year), tonumber(month), tonumber(day)
if not year then -- si ça ne marche pas, c'est que c'est une date à un autre format, essayer autre chose
return nil
end
if calendar == 'julian' then
year, month, day = formatdate.gregorianToJulian( era .. year, month, day )
end
return {day = day, month = month, year = year, era = era, timestamp = timestamp, type = 'dateobject'}
end
 
function p.splitDate(d)
if not d then
return nil
end
if type(d) == 'table' then
return d
end
if tonumber(string.sub(d, 1, 1) ) then -- on suppose par défaut une date ap JC
d = '+' .. d
end
return splitWDdate(d)
end
 
function p.before(a, b) -- return true if b is before a
a = splitDate(a)
b = splitDate(b)
if (not a) or (not b) then
return true
end
if b.era < a.era then
return true
elseif b.year < a.year then
return true
elseif b.month < a.month then
return true
elseif b.day < a.day then
return true
end
return false
end
 
return p