Module:SetDateRange: Difference between revisions
From Seven Sages of Rome
No edit summary |
No edit summary Tag: Manual revert |
||
(7 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {}; | local p = {}; | ||
local function isStringSet(s) | |||
return s ~= nil and s ~= '' | |||
end | |||
p.set = function( f ) | p.set = function( f ) | ||
Line 8: | Line 12: | ||
local args = f.args | local args = f.args | ||
local | local start_date = args.start_date:gsub("-", "/") | ||
local end_date = args.end_date:gsub("-", "/") | |||
local date_range = "" | |||
local date_range = | |||
local date_range_property = args.date_range_property | local date_range_property = args.date_range_property | ||
local sort_date_property = args.sort_date_property | local sort_date_property = args.sort_date_property | ||
if start_date and end_date then | if isStringSet(start_date) and isStringSet(end_date) then | ||
date_range = start_date .. "-" .. end_date | date_range = start_date .. " - " .. end_date | ||
elseif start_date then | elseif isStringSet(start_date) then | ||
date_range = start_date | date_range = start_date | ||
elseif end_date then | elseif isStringSet(end_date) then | ||
date_range = end_date | date_range = end_date | ||
end | end | ||
Line 36: | Line 38: | ||
end | end | ||
return | return date_range | ||
end | end | ||
return p | return p |
Revision as of 14:06, 17 June 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 start_date = args.start_date:gsub("-", "/")
local end_date = args.end_date:gsub("-", "/")
local date_range = ""
local date_range_property = args.date_range_property
local sort_date_property = args.sort_date_property
if isStringSet(start_date) and isStringSet(end_date) then
date_range = start_date .. " - " .. end_date
elseif isStringSet(start_date) then
date_range = start_date
elseif isStringSet(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
return p