Module:ThisWeekInFinancialHistory

-- Provides daily events for the specified week or month.

local p = {}					-- page interface

-- Current week number function p.GetCurrentWeekNumber(frame) return 	os.date( "%W" )		-- return week number of year, based on ISO-8601 end

-- List events for a specified week function p.ListEventsInWeek(frame)

local t = {}					-- table holding articles local utc_timestamp, current_day_number; local day_in_Seconds = 86400;	-- number of seconds in a day local day = tonumber(frame.args['day']);			-- Day as number local month = frame.args['month'];		-- Day of month as full name local year = os.date('%Y');						-- Current year if (month ~=nil) and (day ~= nil) then			-- If month entered, use specified week local month_string = {['January'] = 1, ['February'] = 2, ['March'] = 3, ['April'] = 4, ['May'] = 5, ['June'] = 6, ['July'] = 7, ['August'] = 8, ['September'] = 9, ['October'] = 10, ['November'] = 11, ['December'] = 12}; month=month_string[month];					-- month as number if (month == nil) then						-- error check return "Error in month" end if (day < 1) or (day > 31) then				-- error check return "Error in day" end utc_timestamp = os.time{year=year, month=month, day=day};	-- use specified date current_day_number = tonumber(os.date ('%w', os.time{year=year, month=month, day=day}));	-- current day of week, Sunday = 0 else utc_timestamp = os.time;					-- use current time current_day_number = tonumber(os.date ('%w', os.time));	-- current day of week, Sunday = 0 end

start_of_week = utc_timestamp - (current_day_number - 1)* day_in_Seconds;	-- Start of week, Monday end_of_week = start_of_week + 6 * day_in_Seconds;						-- End of week, 7 days for event_time = start_of_week, end_of_week, day_in_Seconds do			-- for each day in the week article_month = os.date ('%B', event_time);							-- month as name article_day = tonumber(os.date ('%d', event_time));					-- day as zero suppressed number title = "Anniversaries/".. article_month .. "_" .. article_day;		-- title without namespace if mw.title.makeTitle(mw.site.namespaces.Project.name, title).exists == true then	-- if page exists in Project (Bogleheads) namespace table.insert(t, mw.title.makeTitle( mw.site.namespaces.Project.name, title):getContent);	-- add page end -- if						-- otherwise, skip to next day end -- for if next (t) == nil then				-- No events listed, table is empty return "No events are listed for this week." end -- if empty

return frame:preprocess(table.concat(t))	-- table to sequence, process wikitext (transclusion) end -- function

-- List events for a specified month function p.ListEventsInMonth(frame)

local t = {}					-- table holding articles local utc_timestamp, current_day_number; local day_in_Seconds = 86400;	-- number of seconds in a day

local month_string = frame.args['month'];	-- month as full name local year = os.date('%Y');			-- Current year local month_table = {['January'] = 1, ['February'] = 2, ['March'] = 3, ['April'] = 4, ['May'] = 5, ['June'] = 6, ['July'] = 7, ['August'] = 8, ['September'] = 9, ['October'] = 10, ['November'] = 11, ['December'] = 12}; month=month_table[month_string];			-- month as number if (month == nil) then						-- error check return "Error in month" end

-- There's no need to check for the number of days in a month. If the page doesn't exist, it's skipped. utc_timestamp = os.time{year=year, month=month, day=1};			-- current server time (UTC), POSIX (Unix) format start_of_week = utc_timestamp;				-- starts on the first of the month end_of_week = start_of_week + 31 * day_in_Seconds;		-- End of month, 31 days max

for event_time = start_of_week, end_of_week, day_in_Seconds do			-- for each day in the week article_month = os.date ('%B', event_time);							-- month as name article_day = tonumber(os.date ('%d', event_time));					-- day as zero suppressed number title = "Anniversaries/".. article_month .. "_" .. article_day;		-- title without namespace if mw.title.makeTitle(mw.site.namespaces.Project.name, title).exists == true then	-- if page exists in Project (Bogleheads) namespace table.insert(t, mw.title.makeTitle( mw.site.namespaces.Project.name, title):getContent);	-- add page end -- if						-- otherwise, skip to next day end -- for return frame:preprocess(table.concat(t))	-- table to sequence, process wikitext (transclusion) end -- function return p