Module:Calendar date/sandbox: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 174:
]]
function renderHoli(isAvailcfg,iteventdata,jsoncfg,jsonlocalcalcdate,date,df,format,tname,cite,usercalc)
 
local hits = 0
Line 182:
 
-- user-supplied date calculator
if isAvailcfg.datatype == "calculator" then
if jsoncfg.main.event[it]cfg.datasource then
startdate = jsoncfg.main.event[it].datasourcecalcdate
enddate = dateOffset(startdate, jsoncfg.main.event[it]cfg.days - 1)
else
return inlineError("holiday", 'Invalid calculator result', tname )
Line 191:
 
-- read dates from localfile -- it assumes dates in the json are in chrono order, needs a more flexible method
elseif isAvailcfg.datatype == "localfile" then
local numRecords = tableLength(jsonlocal.itemseventdata) -- Get first and last date of holiday
for i = 1, numRecords do
if mw.ustring.find( jsonlocal.itemseventdata[i].date, matchdate ) then
if hits == 0 then
startdate = jsonlocal.itemseventdata[i].date
hits = 1
end
if hits >= tonumber(jsoncfg.main.event[it]cfg.days) then
enddate = jsonlocal.itemseventdata[i].date
break
end
Line 210:
-- Verify data is OK
if startdate == nil or enddate == nil then
if jsoncfg.main.event[it]cfg.holiday == "Hanukkah" and startdate and not enddate then -- Hanukkah bug, template doesn't support cross-year boundary
enddate = dateOffset(startdate, 8)
else
Line 218:
-- Generate start-date offset (ie. holiday starts the evening before the given date)
if jsoncfg.main.event[it]cfg.startoffset then
startdate = dateOffset(startdate, jsoncfg.main.event[it]cfg.startoffset)
if startdate ~= enddate then
enddate = dateOffset(enddate, jsoncfg.main.event[it]cfg.startoffset)
else
jsoncfg.main.event[it]cfg.days = (jsoncfg.main.event[it]cfg.days == "1") and "2"
end
end
-- Generate end-date outside-Irael offset (ie. outside Israel the holiday ends +1 day later)
endoutoffset = jsoncfg.main.event[it]cfg.endoutoffset and dateOffset(enddate, jsoncfg.main.event[it]cfg.endoutoffset)
 
-- Format dates into df format
Line 250:
 
-- return output
if startdate == enddate or jsoncfg.main.event[it]cfg.days == "1" then -- single date
return jsoncfg.main.event[it]cfg.prepend1 .. startdate .. endoutoffset .. cite
else
return jsoncfg.main.event[it]cfg.prepend1 .. startdate .. format .. jsoncfg.main.event[it]cfg.prepend2 .. enddate .. endoutoffset .. cite
end
end
 
--[[--------------------------< isHolidayAvail >-----------------------
 
Given the Configuration.js and name of a holiday, return value of jsoncfg.main.event[it].datatype and index number
Return nil if no holiday found
]]
 
function isHolidayAvail(jsoncfg, holiday)
 
local numRecords = tableLength(jsoncfg.main.event)
for it = 1, numRecords do
if jsoncfg.main.event[it].holiday:lower() == holiday:lower() then
if jsoncfg.main.event[it].datatype:lower() == "calculator" then
return "calculator", it
elseif jsoncfg.main.event[it].datatype:lower() == "localfile" or jsoncfg.main.event[it].datatype:lower() == "local file" then
return "localfile", it
else
return nil, nil
end
end
end
return nil, nil
end
 
--[[--------------------------< calendardate >-----------------------
Line 340 ⟶ 318:
if cfg[holiday].datatype == "localfile" then
eventfile = mw.loadData ('Module:Calendar date/localfiles/' .. holiday)
if eventfile.event[date] then
eventdata = eventfile.event[date]
--local year, month, day = eventdata.date:match ('(%d%d%d%d)-(%d%d)-(%d%d)')
--if not isValidDate(year, month, day) then
-- return inlineError("holiday", '{{Calendar date}} – invalid date ' .. calcdate, tname) .. createTracking()
--end
else
return inlineError("holiday", '{{Calendar date}} – unknown holiday file Module:Calendar date/localfiles/' .. holiday .. '</span>', tname) .. createTracking()