Module:SetDateRange: Difference between revisions

From Seven Sages of Rome
No edit summary
No edit summary
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {};  
local p = {};  


p.setDateRange = function( f )
local function isStringSet(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 args = f.args
local date_range = nil
if args.start_date and args.end_date then
local fixed_date = args.fixed_date:gsub("-", "/")
date_range = args.start_date .. "-" .. args.end_date
local start_date = args.start_date:gsub("-", "/")
elseif args.start_date then
local end_date = args.end_date:gsub("-", "/")
date_range = args.start_date
elseif args.end_date then
local date_range = ""
date_range = args.end_date
local sort_date = ""
local date_range_property = args.date_range_property
local sort_date_property = args.sort_date_property
if isStringSet(fixed_date) then
date_range = fixed_date
sort_date = fixed_date
elseif isStringSet(start_date) and isStringSet(end_date) then
date_range = start_date .. " - " .. end_date
sort_date = start_date
elseif isStringSet(start_date) then
date_range = start_date
sort_date = start_date
elseif isStringSet(end_date) then
date_range = end_date
sort_date = end_date
end
local property = {}
property[sort_date_property] = sort_date
property[date_range_property] = date_range
local result = mw.smw.set( property )
if result == false then
print("Error: Couldn't set date range")
end
end
return date_range
return date_range
end
end


return p
return p

Latest revision as of 19:30, 28 October 2024

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

local p = {}; 

local function isStringSet(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 fixed_date = args.fixed_date:gsub("-", "/")
	local start_date = args.start_date:gsub("-", "/")
	local end_date = args.end_date:gsub("-", "/")
	
	local date_range = ""
	local sort_date = ""
	
	local date_range_property = args.date_range_property
	local sort_date_property = args.sort_date_property
	
	if isStringSet(fixed_date) then
		date_range = fixed_date
		sort_date = fixed_date
	elseif isStringSet(start_date) and isStringSet(end_date) then
		date_range = start_date .. " - " .. end_date
		sort_date = start_date
	elseif isStringSet(start_date) then
		date_range = start_date
		sort_date = start_date
	elseif isStringSet(end_date) then
		date_range = end_date
		sort_date = end_date
	end
	
	local property = {}
	property[sort_date_property] = sort_date
	property[date_range_property] = date_range
	
	local result = mw.smw.set( property )
	
	if result == false then
		print("Error: Couldn't set date range")
	end
	
	return date_range
end

return p