Documentation icon Dokumentacija modula[predogled] [uredi] [zgodovina] [osveži]

Primeri klica funkcije dateOfBirth uredi

  • {{#invoke:Infocards|dateOfBirth|-382|−336}} → 382 pr. n. št.({{padleft:-382|4|0}})
  • {{#invoke:Infocards|dateOfBirth|11.1|}} → 11. januar
  • {{#invoke:Infocards|dateOfBirth|24.12.3|15.01.69}} → 24. december 3({{padleft:3|4|0}}-{{padleft:12|2|0}}-{{padleft:24|2|0}})
  • {{#invoke:Infocards|dateOfBirth|23.09.-63|19.08.14}} → 23. september 63 pr. n. št.({{padleft:-63|4|0}}-{{padleft:9|2|0}}-{{padleft:23|2|0}})
  • {{#invoke:Infocards|dateOfBirth|42|9.6.42}} → 42({{padleft:42|4|0}})
  • {{#invoke:Infocards|dateOfBirth|870|13.8.900}} → 870({{padleft:870|4|0}})
  • {{#invoke:Infocards|dateOfBirth||22.01.984}} →
  • {{#invoke:Infocards|dateOfBirth|16.06.1066|datum smrti ni znan}} → 16. junij 1066({{padleft:1066|4|0}}-{{padleft:6|2|0}}-{{padleft:16|2|0}})
  • {{#invoke:Infocards|dateOfBirth|8.2.1834 (27.1)|2.2.1907 (20.1)}} → 27. januar (8. februar) 1834({{padleft:1834|4|0}}-{{padleft:2|2|0}}-{{padleft:8|2|0}})
  • {{#invoke:Infocards|dateOfBirth|29.06.1844 (17)|28.10.1883 (16)}} → 17. (29.) junij 1844({{padleft:1844|4|0}}-{{padleft:6|2|0}}-{{padleft:29|2|0}})
  • {{#invoke:Infocards|dateOfBirth|19.7.1893 (7)|}} → 7. (19.) julij 1893({{padleft:1893|4|0}}-{{padleft:7|2|0}}-{{padleft:19|2|0}})
  • {{#invoke:Infocards|dateOfBirth|3.10.1895 (21.9)|28.12.1925}} → 21. september (3. oktober) 1895({{padleft:1895|4|0}}-{{padleft:10|2|0}}-{{padleft:3|2|0}})
  • {{#invoke:Infocards|dateOfBirth|4.10.1916|8.11.2009}} → 4. oktober 1916({{padleft:1916|4|0}}-{{padleft:10|2|0}}-{{padleft:4|2|0}})
  • {{#invoke:Infocards|dateOfBirth|09.06.1942|}} → 9. junij 1942({{padleft:1942|4|0}}-{{padleft:6|2|0}}-{{padleft:9|2|0}}) (81 let)
  • {{#invoke:Infocards|dateOfBirth|1955|}} → 1955({{padleft:1955|4|0}})
  • {{#invoke:Infocards|dateOfBirth|29.02.1984|}} → 29. februar 1984({{padleft:1984|4|0}}-{{padleft:2|2|0}}-{{padleft:29|2|0}}) (40 let)
  • {{#invoke:Infocards|dateOfBirth||}} →
  • {{#invoke:Infocards|dateOfBirth|4.1.1885 (23.12.1884)|17.5.1951}} → 23. december 1884 (4. januar 1885)({{padleft:1885|4|0}}-{{padleft:1|2|0}}-{{padleft:4|2|0}})
  • {{#invoke:Infocards|dateOfBirth|{{Datum rojstva|3|12|24}}|{{Datum smrti|69|01|15}}}} → (3-12-24)24. december 3
  • {{#invoke:Infocards|dateOfBirth|cca. leta [[5]]|24.01.41}} → cca. leta 5
  • {{#invoke:Infocards|dateOfBirth|cca. leta [[5]]|{{Datum smrti|41|01|24}}}} → cca. leta 5
  • {{#invoke:Infocards|dateOfBirth|[[868]]/[[872]]|[[15. september]]/[[15. november]] [[890]]}} → 868/872
  • {{#invoke:Infocards|dateOfBirth|{{Datum rojstva|1834|2|8|1|27}}|{{Datum smrti|1907|2|2|1|20}} (72 let)}} → (1834-02-08)8. februar 1834

Primeri klica funkcije dateOfDeath uredi

  • {{#invoke:Infocards|dateOfDeath|-382|−336}} → 336 pr. n. št.({{padleft:-336|4|0}})
  • {{#invoke:Infocards|dateOfDeath|24.12.3|15.01.69}} → 15. januar 69({{padleft:69|4|0}}-{{padleft:1|2|0}}-{{padleft:15|2|0}}) (65 let)
  • {{#invoke:Infocards|dateOfDeath|23.09.-63|19.08.14}} → 19. avgust 14({{padleft:14|4|0}}-{{padleft:8|2|0}}-{{padleft:19|2|0}}) (76 let)
  • {{#invoke:Infocards|dateOfDeath|42|9.6.42}} → 9. junij 42({{padleft:42|4|0}}-{{padleft:6|2|0}}-{{padleft:9|2|0}})
  • {{#invoke:Infocards|dateOfDeath|870|13.8.900}} → 13. avgust 900({{padleft:900|4|0}}-{{padleft:8|2|0}}-{{padleft:13|2|0}})
  • {{#invoke:Infocards|dateOfDeath||22.01.984}} → 22. januar 984({{padleft:984|4|0}}-{{padleft:1|2|0}}-{{padleft:22|2|0}})
  • {{#invoke:Infocards|dateOfDeath|16.06.1066|datum smrti ni znan}} → datum smrti ni znan
  • {{#invoke:Infocards|dateOfDeath|8.2.1834 (27.1)|2.2.1907 (20.1)}} → 20. januar (2. februar) 1907({{padleft:1907|4|0}}-{{padleft:2|2|0}}-{{padleft:2|2|0}}) (72 let)
  • {{#invoke:Infocards|dateOfDeath|29.06.1844 (17)|28.10.1883 (16)}} → 16. (28.) oktober 1883({{padleft:1883|4|0}}-{{padleft:10|2|0}}-{{padleft:28|2|0}}) (39 let)
  • {{#invoke:Infocards|dateOfDeath|19.7.1893 (7)|}} → 14. april 1930({{padleft:1930|4|0}}-{{padleft:4|2|0}}-{{padleft:14|2|0}}) (36 let)
  • {{#invoke:Infocards|dateOfDeath|3.10.1895 (21.9)|28.12.1925}} → 28. december 1925({{padleft:1925|4|0}}-{{padleft:12|2|0}}-{{padleft:28|2|0}}) (30 let)
  • {{#invoke:Infocards|dateOfDeath|4.10.1916|8.11.2009}} → 8. november 2009({{padleft:2009|4|0}}-{{padleft:11|2|0}}-{{padleft:8|2|0}}) (93 let)
  • {{#invoke:Infocards|dateOfDeath|09.06.1942|}} →
  • {{#invoke:Infocards|dateOfDeath|1955|}} →
  • {{#invoke:Infocards|dateOfDeath|29.02.1984|}} →
  • {{#invoke:Infocards|dateOfDeath||}} →
  • {{#invoke:Infocards|dateOfDeath|{{Datum rojstva|3|12|24}}|{{Datum smrti|69|01|15}}}} → 15. januar 69(69-01-15)
  • {{#invoke:Infocards|dateOfDeath|cca. leta [[5]]|24.01.41}} → 24. januar 41({{padleft:41|4|0}}-{{padleft:1|2|0}}-{{padleft:24|2|0}})
  • {{#invoke:Infocards|dateOfDeath|cca. leta [[5]]|{{Datum smrti|41|01|24}}}} → 24. januar 41(41-01-24)
  • {{#invoke:Infocards|dateOfDeath|[[868]]/[[872]]|[[15. september]]/[[15. november]] [[890]]}} → 15. september/15. november 890
  • {{#invoke:Infocards|dateOfDeath|{{Datum rojstva|1834|8|2|1|27}}|{{Datum smrti|1907|2|2|1|20}} (72 let)}} → 2. februar 1907(1907-02-02) (72 let)

Primeri klica funkcije isDate uredi

  • {{#invoke:Infocards|isDate||TRUE|FALSE}} → FALSE
  • {{#invoke:Infocards|isDate|-382|TRUE|FALSE}} → TRUE
  • {{#invoke:Infocards|isDate|−336|TRUE|FALSE}} → TRUE
  • {{#invoke:Infocards|isDate|24.12.3|TRUE|FALSE}} → TRUE
  • {{#invoke:Infocards|isDate|19.7.1893 (7)|TRUE|FALSE}} → TRUE
  • {{#invoke:Infocards|isDate|19.7.67.18/93 (7)|TRUE|FALSE}} → FALSE
  • {{#invoke:Infocards|isDate|13. december 2005|TRUE|FALSE}} → FALSE
  • {{#invoke:Infocards|isDate|datum smrti ni znan|TRUE|FALSE}} → FALSE
  • {{#invoke:Infocards|isDate|{{Datum rojstva|3|24|12}}|TRUE|FALSE}} → FALSE
local infocards = {};
local calculateAge = true;

--[[
Helper function that populates the argument list given that user may need to use a mix of
named and unnamed parameters.  This is relevant because named parameters are not
identical to unnamed parameters due to string trimming, and when dealing with strings
we sometimes want to either preserve or remove that whitespace depending on the application.
]]
function infocards._getParameters( frame_args, arg_list )
    local new_args = {};
    local index = 1;
    local value;
 
    for i,arg in ipairs( arg_list ) do
        value = frame_args[arg]
        if value == nil then
            value = frame_args[index];
            index = index + 1;
        end
        new_args[arg] = value;
    end
 
    return new_args;
end        

function infocards.isBlank( someString )
    return someString == nil or mw.ustring.match(someString, '^%s*$') ~= nil;
end

function infocards.isDate ( frame )
    local new_args = infocards._getParameters( frame.args, {'s', 't', 'f'} );
    local s = new_args['s'] or '';
    local t = new_args['t'] or '';
    local f = new_args['f'] or '';

    local result = infocards.isDateImpl ( s )
    if (result) then
        return t
    else
        return f
    end
end

function infocards.isDateImpl ( s )
    local converted = infocards.convertToDate ( s );
    return converted ~= nil
end

function infocards.dateOfBirth( frame )
    local new_args = infocards._getParameters( frame.args, {'dateOfBirth', 'dateOfDeath', 'nocat'} );
    local dateOfBirth = new_args['dateOfBirth'] or '';
    local dateOfDeath = new_args['dateOfDeath'] or '';
    local nocat = new_args['nocat'] or mw.title.getCurrentTitle().nsText;

    return infocards.dateOfBirthImpl( dateOfBirth, dateOfDeath, nocat );
end

function infocards.dateOfBirthImpl( dateOfBirth, dateOfDeath, nocat )

    local appendToCategory = infocards.isBlank( nocat );

    if ( infocards.isBlank( dateOfBirth ) ) then
        if ( appendToCategory ) then
            return '[[Kategorija:Manjka datum rojstva]]'
        else
            return ''
        end
    end

    if ( mw.ustring.match( dateOfBirth, '^%s*неизвестн.%s*$' ) ~= nil
            or mw.ustring.match( dateOfBirth, '^%s*%?%s*$' ) ~= nil ) then
        if ( appendToCategory ) then
            return "''neznano''[[Kategorija:Manjka leto rojstva]]"
        else
            return "''neznano''"
        end
    end

    local appendAge = calculateAge and infocards.isBlank( dateOfDeath );

    local parsedDate = infocards.convertToDate ( dateOfBirth )
    if ( parsedDate == nil ) then
        if ( appendToCategory ) then
            return dateOfBirth .. '[[Kategorija:Članki z ročno vnesenimi datumi v infopolju]]'
        else
            return dateOfBirth
        end
    end

    local result = infocards.formatDateImpl ( parsedDate, 'bday', appendToCategory and 'Rojeni' or nil )

    if ( appendAge ) then
        local age = infocards.age ( parsedDate,  os.date("*t") )
        if ( age > 0 ) then
            result = result .. ' <span style="white-space:nowrap;">(' .. age .. ' ' .. mw.language.new( 'sl' ):plural( age, 'leto','leta','let') .. ')</span>'
        end
        if ( age > 150 and appendToCategory ) then
            result = result .. '[[Kategorija:Previsoka trenutna starost]]'
        end
    end

    return result
end

function infocards.dateOfDeath( frame )
    local new_args = infocards._getParameters( frame.args, {'dateOfBirth', 'dateOfDeath', 'nocat'} );
    local dateOfBirth = new_args['dateOfBirth'] or '';
    local dateOfDeath = new_args['dateOfDeath'] or '';
    local nocat = new_args['nocat'] or mw.title.getCurrentTitle().nsText;

    return infocards.dateOfDeathImpl( dateOfBirth, dateOfDeath, nocat );
end

function infocards.dateOfDeathImpl( dateOfBirth, dateOfDeath, nocat )
    if ( infocards.isBlank( dateOfDeath ) ) then
        return ''
    end

    local appendToCategory = infocards.isBlank( nocat );

    if ( mw.ustring.match( dateOfDeath, '^%s*неизвестн.%s*$' ) ~= nil
            or mw.ustring.match( dateOfDeath, '^%s*%?%s*$' ) ~= nil ) then
        if ( appendToCategory ) then
            return "''neznano''[[Kategorija:Manjka datum smrti]]"
        else
            return "''neznano''"
        end
    end

    local parsedDateOfBirth = infocards.convertToDate ( dateOfBirth )
    local parsedDateOfDeath = infocards.convertToDate ( dateOfDeath )

    if ( parsedDateOfDeath == nil ) then
        if ( appendToCategory ) then
            return dateOfDeath .. '[[Kategorija:Članki z ročno vnesenimi datumi v infopolju]]'
        else
            return dateOfDeath
        end
    end

    local result = infocards.formatDateImpl ( parsedDateOfDeath, 'dday', appendToCategory and 'Umrli' or nil )

	if ( calculateAge ) then
		local age = infocards.age ( parsedDateOfBirth, parsedDateOfDeath )
		if ( age > 0 ) then
			result = result .. ' <span style="white-space:nowrap;">(' .. age .. ' ' .. mw.language.new( 'sl' ):plural( age, 'leto','leta','let') .. ')</span>'
		end
		if ( age > 150 and appendToCategory ) then
			result = result .. '[[Kategorija:Previsoka starost ob smrti]]'
		end
	end

    return result
end

function infocards.age( parsedBirthDate, parsedFinishDate ) 
    if ( parsedBirthDate == nil or parsedFinishDate == nil ) then
        return 0
    end

    local bd = parsedBirthDate["day"]
    local bm = parsedBirthDate["month"]
    local by = parsedBirthDate["year"]

    local dd = parsedFinishDate["day"];
    local dm = parsedFinishDate["month"];
    local dy = parsedFinishDate["year"];

    if ( bd and bm and by and dd and dm and dy ) then
        if ( dm > bm or ( dm == bm and dd >= bd ) ) then
            return dy - by
        else
            return dy - by - 1
        end
    else
        return 0
    end
end

local genitivusMonthes = {'januarja', 'februarja', 'marca', 'aprila', 'maja', 'junija',
    'julija', 'avgusta', 'septembra', 'oktobra', 'novembra', 'decembra'}

local nominativeMonthes = {'januar', 'februar', 'marec', 'april', 'maj', 'junij',
    'julij', 'avgust', 'september', 'oktober', 'november', 'december'}

function infocards.formatDateImpl( parsedDate, infocardClass, categoryNamePrefix )
    local nd = parsedDate["day"];
    local nm = parsedDate["month"];
    local ny = parsedDate["year"];
    local od = parsedDate["osday"];
    local om = parsedDate["osmonth"];
    local oy = parsedDate["osyear"];
    
    local template =
        (nd ~= nil and "1" or "") .. (nm ~= nil and "2" or "") .. (ny ~= nil and "3" or "") ..
        (od ~= nil and "4" or "") .. (om ~= nil and "5" or "") .. (oy ~= nil and "6" or "")

    local datePart = '<span style="white-space:nowrap;">'
    if (template == "12") then
        datePart = datePart .. string.format( "[[%d. %s]]", nd, nominativeMonthes[nm] )
    elseif (template == "3") then
        datePart = datePart .. infocards.nominativeYear( ny )
    elseif (template == "123") then
        datePart = datePart .. string.format( "[[%d. %s]] %s",
                                        nd, nominativeMonthes[nm], infocards.nominativeYear( ny ) )
    elseif (template == "124") then
        datePart = datePart .. string.format( "[[%d. %s|%d. (%d.) %s]]",
                                        nd, nominativeMonthes[nm], od, nd, nominativeMonthes[nm] )
    elseif (template == "1234") then
        datePart = datePart .. string.format( "[[%d. %s|%d. (%d.) %s]] %s",
                                        nd, nominativeMonthes[nm], od, nd, nominativeMonthes[nm], infocards.nominativeYear( ny ) )
    elseif (template == "1245") then
        datePart = datePart .. string.format( "%d. %s ([[%d. %s]])",
                                        od, nominativeMonthes[om], nd, nominativeMonthes[nm] )
    elseif (template == "12345") then
        datePart = datePart .. string.format( "%d. %s ([[%d. %s]]) %s",
                                        od, nominativeMonthes[om], nd, nominativeMonthes[nm], infocards.nominativeYear( ny ) )
    elseif (template == "123456") then
        datePart = datePart .. string.format( '%d. %s %d</span> <span style="white-space:nowrap;">([[%d. %s]] %s)',
                                        od, nominativeMonthes[om], oy, nd, nominativeMonthes[nm], infocards.nominativeYear( ny ) )
    else
        datePart = datePart .. 'mepoznan format'
    end
    datePart = datePart .. '</span>'

    local infocardTemplate =
        (nd ~= nil and "1" or "") .. (nm ~= nil and "2" or "") .. (ny ~= nil and "3" or "")

    if (infocardTemplate == "123") then
        datePart = datePart .. '<span style="display:none">(<span class="' .. infocardClass .. '">{{padleft:' .. ny .. '|4|0}}-{{padleft:' .. nm .. '|2|0}}-{{padleft:' .. nd .. '|2|0}}</span>)</span>'
    elseif (infocardTemplate == "23") then
        datePart = datePart .. '<span style="display:none">(<span class="' .. infocardClass .. '">{{padleft:' .. ny .. '|4|0}}-{{padleft:' .. nm .. '|2|0}}</span>)</span>'
    elseif (infocardTemplate == "3") then
        datePart = datePart .. '<span style="display:none;">(<span class="' .. infocardClass .. '">{{padleft:' .. ny .. '|4|0}}</span>)</span>'
    end

    if ( categoryNamePrefix ~= nil ) then
        if ( nd ~= nil and nm ~= nil) then
            datePart = datePart .. '[[Kategorija:' .. categoryNamePrefix .. ' ' .. nd .. '. ' .. genitivusMonthes[nm] .. ']]'
        end
        if ( ny ~= nil) then
            datePart = datePart .. '[[Kategorija:' .. categoryNamePrefix .. ' leta ' .. infocards.inYear( ny ) .. ']]'
        end
    end

    return datePart
end

function infocards.nominativeYear( year )
    if ( year >= 0 ) then
        return '[[' .. year .. '|' .. year .. ']]'
    else
        return '[[' .. ( 0 - year ) .. ' pr. n. št.|' .. ( 0 - year ) .. ' pr. n. št.]]'
    end
end

function infocards.inYear( year )
    if ( year >= 0 ) then
        return '' .. year .. ''
    else
        return '' .. ( 0 - year) .. ' pr. n. št.'
    end
end

function infocards.convertToDate( possibleDateString )

    possibleDateString = mw.ustring.gsub( possibleDateString, '−', '-')

    local simpleDate = mw.ustring.match(possibleDateString, '^%s*([%-%d%.]+)%s*$', 0)
    if ( simpleDate ) then
        return infocards.convertToDateNewStylePart( simpleDate );
    end

    local complexDate1, complexDate2 = mw.ustring.match(possibleDateString, '^%s*([%-%d%.]+)%s*%(([%-%d%.]+)%)%s*$', 0)
    if ( complexDate1 and complexDate2) then
        local table1 = infocards.convertToDateNewStylePart( complexDate1 );
        local table2 = infocards.convertToDateOldStylePart( complexDate2 );
        if ( table1 and table2 ) then
            return {
                    year = table1["year"], month = table1["month"], day = table1["day"], 
                    osyear = table2["year"], osmonth = table2["month"], osday = table2["day"]
                }
        else
            return nil
        end
    end

    return nil
end

function infocards.convertToDateNewStylePart( possibleDateString )

    local ny = mw.ustring.match(possibleDateString, '^(%-?%d+)$', 0)
    if (ny ~= nil) then
        return {year = tonumber(ny)}
    end

    return infocards.convertToDateCommonPart( possibleDateString )
end

function infocards.convertToDateOldStylePart( possibleDateString )

    local nd = mw.ustring.match(possibleDateString, '^(%-?%d+)$', 0)
    if (nd ~= nil) then
        return {day = tonumber(nd)}
    end

    return infocards.convertToDateCommonPart( possibleDateString )
end


function infocards.convertToDateCommonPart( possibleDateString )

    local nd, nm
        = mw.ustring.match(possibleDateString, '^(%d?%d)%.(%d?%d)$', 0)
    if (nd ~= nil and nm ~= nil) then
        return {day = tonumber(nd), month = tonumber(nm)}
    end

    local nd, nm, ny
        = mw.ustring.match(possibleDateString, '^(%d?%d)%.(%d?%d)%.(%-?%d+)$', 0)
    if (nd ~= nil and nm ~= nil and ny ~= nil) then
    	local ndn = tonumber(nd)
    	local nmn = tonumber(nm)
    	local nyn = tonumber(ny)
    	if (ndn > 0 and ndn < 33 and nmn > 0 and nmn < 13) then
        	return {day = ndn, month = nmn, year = nyn}
        end
    end

    return nil
end

return infocards