Přeskočit na obsah

Modul:VerbalDate

Z Wikizpráv

Dokumentaci tohoto modulu lze vytvořit na stránce Nápověda:Modul:VerbalDate

-- @brief
--  Handling of verbal dates.
-- 
-- @details
--  Handles the verbal dates.
--  Currently supports
--  * month names
--  * month genitives
-- 
-- @author
--  [[meta:User:Danny B.]]
local VerbalDate = {}
----------------------------------------


VerbalDate.months = {
    {
		name = "leden",
		genitive = "ledna"
	}, {
		name = "únor",
		genitive = "února"
	}, {
		name = "březen",
		genitive = "března"
	}, {
		name = "duben",
		genitive = "dubna"
	}, {
		name = "květen",
		genitive = "května"
	}, {
		name = "červen",
		genitive = "června"
	}, {
		name = "červenec",
		genitive = "července"
	}, {
		name = "srpen",
		genitive = "srpna"
	}, {
		name = "září",
		genitive = "září"
	}, {
		name = "říjen",
		genitive = "října"
	}, {
		name = "listopad",
		genitive = "listopadu"
	}, {
		name = "prosinec",
		genitive = "prosince"
	}
}


-- @brief
--  Creates the datestamp.
-- 
-- @return
--  String Datestamp (YYYY-MM-DD)
function VerbalDate.toDatestamp()
	
    local output = ""
	local _, day, monthname, year, month
	
	_, _, day, monthname, year = string.find( mw.title.getCurrentTitle().text, "(%d+)%. ?(.-) (%d+)" )

    if ( day and monthname and year ) then
        for index, value in ipairs( VerbalDate.months ) do
		    if ( value.name == monthname or value.genitive == monthname ) then
			    month = index
		    end
            if ( month ) then
                output = string.format( "%04d-%02d-%02d", year, month, day)
            end
        end
    end
	
	return output
	
end


-- @brief
--  Creates the (midnight) timestamp.
-- 
-- @return
--  String Timestamp (YYYYMMDD000000)
function VerbalDate.toTimestamp()
    
    local output = ""
	local _, day, monthname, year, month
	
	_, _, day, monthname, year = string.find( mw.title.getCurrentTitle().text, "(%d+)%. ?(.-) (%d+)" )

    if ( day and monthname and year ) then
        for index, value in ipairs( VerbalDate.months ) do
		    if ( value.name == monthname or value.genitive == monthname ) then
			    month = index
		    end
            if ( month ) then
                output = string.format( "%04d%02d%02d000000", year, month, day)
            end
        end
    end
	
	return output
	
end


----------------------------------------
return VerbalDate