Module:SetDateRange

From Seven Sages of Rome
Revision as of 12:12, 17 June 2024 by Noeth (talk | contribs)

Documentation for this module may be created at Module:SetDateRange/doc

local p = {}; 

local function isSet(s)
	return s ~= nil and s ~= ''
end

p.set = function( f )
	if not mw.smw then
        return "mw.smw module not found"
	end

	local args = f.args
	
	local start_date = args.start_date
	local end_date = args.end_date
	
	local date_range = ""
	
	local date_range_property = args.date_range_property
	local sort_date_property = args.sort_date_property
	
	if isSet(start_date) and isSet(end_date) then
		date_range = start_date .. "-" .. end_date
	elseif isSet(start_date) then
		date_range = start_date
	elseif isSet(end_date) then
		date_range = end_date
	end
	
	local property = {}
	property[date_range_property] = date_range
	property[sort_date_property] = start_date
	
	local result = mw.smw.set( property )
	
	if result == false then
		print("Error: Couldn't set date range")
	end
	
	return date_range
end

p.test = function( f )
	return "test"
end

return p