Module:ThisWeekInFinancialHistory

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

local p = {}					-- page interface

-- Returns the number of days in the month where month is a number 1–12 and year is four-digit Gregorian calendar. -- Accounts for leap year. From Wikipedia: Module:Time local function get_days_in_month (year, month) local days_in_month = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; year = tonumber (year);														-- force these to be numbers just in case month = tonumber (month);

if (2 == month) then														-- if February if (0 == (year%4) and (0 ~= (year%100) or 0 == (year%400))) then		-- is year a leap year? return 29;															-- if leap year then 29 days in February end end return days_in_month [month]; end

-- Current week number function p.GetCurrentWeekNumber(frame) return 	os.date( "%V" )		-- 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

if (current_day_number == 0) then				-- correct for Sunday current_day_number = 7; 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

utc_timestamp = os.time{year=year, month=month, day=1};			-- current server time (UTC), POSIX (Unix) format days_in_month = get_days_in_month (year, month);			-- number of days in month start_of_month = utc_timestamp;				-- starts on the first of the month end_of_month = start_of_month + (days_in_month - 1) * day_in_Seconds;		-- End of month

for event_time = start_of_month, end_of_month, day_in_Seconds do		-- for each day in the month 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