Marvel Database
No edit summary
No edit summary
(20 intermediate revisions by the same user not shown)
Line 8: Line 8:
 
local days_in_month = {31,28,31,30,31,30,31,31,30,31,30,31}
 
local days_in_month = {31,28,31,30,31,30,31,31,30,31,30,31}
   
  +
--------------------------------------------------------------------------------
 
 
-- return full month name
 
-- return full month name
 
function p.get_month_name(frame)
 
function p.get_month_name(frame)
local args = getArgs(frame)
+
local args = getArgs(frame)
local name = args[1]
+
local name = args[1]
local output = nil
+
local output = nil
  +
 
if not h.isempty(name)
+
if not h.isempty(name)
then
+
then
name = mw.text.trim(name)
+
name = mw.text.trim(name)
name = string.gsub(name, '^0', '')
+
name = string.gsub(name, '^0', '')
output = month_names[ string.lower(name) ]
+
output = month_names[ string.lower(name) ]
end
+
end
   
 
return output
 
return output
Line 26: Line 26:
   
   
  +
--------------------------------------------------------------------------------
 
-- return month number
 
-- return month number
 
function p.get_month_number(frame)
 
function p.get_month_number(frame)
local args = getArgs(frame)
+
local args = getArgs(frame)
 
local number = args[1]
 
local number = args[1]
 
local output = nil
 
local output = nil
if not h.isempty(number)
+
if not h.isempty(number)
then
+
then
number = mw.text.trim(number)
+
number = mw.text.trim(number)
number = string.gsub(number, '^0', '')
+
number = string.gsub(number, '^0', '')
output = month_numbers[ string.lower(number) ]
+
output = month_numbers[ string.lower(number) ]
end
+
end
   
 
return output
 
return output
Line 42: Line 43:
   
   
  +
--------------------------------------------------------------------------------
 
--takes a date and formats it according to the syntax - https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions##time
 
--takes a date and formats it according to the syntax - https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions##time
 
function p.lua_date_converter(s_date, s_format)
 
function p.lua_date_converter(s_date, s_format)
local year = nil
+
local year = nil
local month = nil
+
local month = nil
local day = nil
+
local day = nil
local i = 0
+
local i = 0
local j = 0
+
local j = 0
local output = ''
+
local output = ''
  +
 
s_format = s_format or 'Ymd'
+
s_format = s_format or 'Ymd'
  +
 
if h.isempty(s_date) or s_date == 'now'
+
if h.isempty(s_date) or s_date == 'now'
then output = language:formatDate(s_format)
+
then output = language:formatDate(s_format)
else
+
else
month, day, year = string.match(s_date, '(.+) (.+), (%d%d%d%d)')
+
month, day, year = string.match(s_date, '(.+) (.+), (%d%d%d%d)')
if month == nil
+
if month == nil
then month, day, year = string.match(s_date, '(.+)%-(.+)%-(%d%d%d%d)')
+
then month, day, year = string.match(s_date, '(.+)%-(.+)%-(%d%d%d%d)')
  +
end
end
 
if day ~= nil and month ~= nil and year ~= nil
+
if day ~= nil and month ~= nil and year ~= nil
  +
then
then
 
month = p.get_month_number({month})
+
month = p.get_month_number({month})
if #day == 1 then day = '0'..day end
+
if #day == 1 then day = '0'..day end
if s_format == 'Ymd'
+
if s_format == 'Ymd'
then output = year..month..day
+
then output = year..month..day
elseif s_format == 'Ym'
+
elseif s_format == 'Ym'
then output = year..month
+
then output = year..month
elseif s_format == 'F j, Y'
+
elseif s_format == 'F j, Y'
  +
then
then
 
day = string.gsub(day, '^0', '')
+
day = string.gsub(day, '^0', '')
month = p.get_month_name({month})
+
month = p.get_month_name({month})
output = month..' '..day..', '..year
+
output = month..' '..day..', '..year
else output = language:formatDate(s_format, month..' '..day..' '..year)
+
else output = language:formatDate(s_format, month..' '..day..' '..year)
  +
end
end
 
else output = language:formatDate(s_format, s_date)
+
else output = language:formatDate(s_format, s_date)
  +
end
end
 
end
+
end
   
return output
+
return output
 
end
 
end
   
   
  +
--------------------------------------------------------------------------------
 
--compares two dates. Return "true" if 1st date is before the 2nd date, and "false" otherwise.
 
--compares two dates. Return "true" if 1st date is before the 2nd date, and "false" otherwise.
 
function p.lua_date_comparison(date1, date2)
 
function p.lua_date_comparison(date1, date2)
local output
+
local output
  +
 
date1 = p.lua_date_converter(date1, 'Ymd')
+
date1 = p.lua_date_converter(date1, 'Ymd')
if tonumber( string.sub(date1, 1, 4) ) < 2020
+
if tonumber( string.sub(date1, 1, 4) ) < 2020
and ( h.isempty(date2)
+
and ( h.isempty(date2)
or date2 == 'now'
+
or date2 == 'now'
or tonumber( string.sub(p.lua_date_converter(date2, 'Ymd'), 1, 4) ) >= 2020
+
or tonumber( string.sub(p.lua_date_converter(date2, 'Ymd'), 1, 4) ) >= 2020
  +
)
)
 
then output = true
+
then output = true
else
+
else
date2 = p.lua_date_converter(date2 or 'now', 'Ymd') --If 2nd date is ommited, then current date is used for comparison.
+
date2 = p.lua_date_converter(date2 or 'now', 'Ymd') --If 2nd date is ommited, then current date is used for comparison.
output = date1<=date2
+
output = date1<=date2
end
+
end
  +
 
return output
+
return output
 
end
 
end
   
   
  +
--------------------------------------------------------------------------------
 
--returns era based on year
 
--returns era based on year
  +
--[[
 
function p.get_era(frame)
 
function p.get_era(frame)
local args = getArgs(frame)
+
local args = getArgs(frame)
local year = tonumber(args[1])
+
local year = tonumber(args[1])
local key = args[2] or ''
+
local key = args[2] or ''
local output = ''
+
local output = ''
   
if not h.isempty(year)
+
if not h.isempty(year)
then
+
then
if not h.isempty(key) then key = ' '..key end
+
if not h.isempty(key) then key = ' '..key end
if year<1955 then output = 'Golden-Age'..key end
+
if year<1955 then output = 'Golden-Age'..key end
if year>=1955 and year<1970 then output = 'Silver-Age'..key end
+
if year>=1955 and year<1970 then output = 'Silver-Age'..key end
if year>=1970 and year<1983 then output = 'Bronze-Age'..key end
+
if year>=1970 and year<1983 then output = 'Bronze-Age'..key end
if year>=1983 and year<1992 then output = 'Copper-Age'..key end
+
if year>=1983 and year<1992 then output = 'Copper-Age'..key end
if year>=1992 then output = 'Modern-Age'..key end
+
if year>=1992 then output = 'Modern-Age'..key end
end
+
end
  +
 
return output
+
return output
 
end
 
end
  +
]]--
   
  +
--------------------------------------------------------------------------------
  +
function p.lua_get_publication_category(year, month, day)
  +
local link = ''
  +
local category = ''
  +
local text = ''
   
  +
if not h.isempty(year)
function p.lua_get_publication_category(year, month)
 
  +
then
local link = ''
 
  +
month = p.get_month_name({month})
local category = ''
 
  +
if month ~= nil
local text = ''
 
  +
then
 
if not h.isempty(year)
+
if h.isempty(day)
  +
then day = ''
then
 
  +
else day = ' '..day
month = p.get_month_name({month})
 
  +
end
if month ~= nil
 
  +
category = year..', '..month
then
 
category = year..', '..month
+
link = h.LinkToCategory(category, month..day)..', '..h.LinkToCategory(year, year)
  +
text = month..', '..year
link = h.lua_link_to_category(category, month)..', '..h.lua_link_to_category(year)
 
  +
else
text = month..', '..year
 
  +
category = year
else
 
  +
link = h.LinkToCategory(year, year)
category = year
 
  +
text = year
link = h.lua_link_to_category(year)
 
  +
end
text = year
 
  +
end
end
 
  +
end
 
  +
return link, category, text
 
return link, category, text
 
 
end
 
end
   
   
  +
--------------------------------------------------------------------------------
 
-- returns information about release date
 
-- returns information about release date
 
function p.lua_get_release_date_info(release_date)
 
function p.lua_get_release_date_info(release_date)
local recent = false
+
local recent = false
local releaseweek
+
local releaseweek
local text = ''
+
local text = ''
local link = ''
+
local link = ''
local year = ''
+
local year = ''
local month = ''
+
local month = ''
local day = ''
+
local day = ''
local no_day = ''
+
local no_day = ''
local category = ''
+
local category = ''
local output = ''
+
local output = ''
  +
 
if not h.isempty(release_date)
+
if not h.isempty(release_date)
then
+
then
output = p.lua_date_converter(release_date, 'F j, Y')
+
output = p.lua_date_converter(release_date, 'F j, Y')
month, day, year = string.match(output, '(.-) (%d-), (%d%d%d%d)')
+
month, day, year = string.match(output, '(.-) (%d-), (%d%d%d%d)')
no_day = month..', '..year
+
no_day = month..', '..year
link = p.lua_get_link_to_release_week(output)
+
link = p.lua_get_link_to_release_week(output)
text = h.lua_breaklink(link, 1)
+
text = h.break_link(link, 1)
recent = p.lua_is_recently_released(output)
+
recent = p.lua_is_recently_released(output)
end
+
end
   
output = {
+
output = {
date = output,
+
date = output,
week = {
+
week = {
text = text,
+
text = text,
link = link
+
link = link
  +
},
},
 
recent = recent,
+
recent = recent,
day = day,
+
day = day,
month = month,
+
month = month,
year = year,
+
year = year,
no_day = no_day
+
no_day = no_day
  +
}
}
 
   
return output
+
return output
 
end
 
end
   
   
  +
--------------------------------------------------------------------------------
 
-- returns information about publication date
 
-- returns information about publication date
 
function p.lua_get_publication_date_info(year, month, canceled)
 
function p.lua_get_publication_date_info(year, month, canceled)
--local published = true
+
--local published = true
local month_number
+
local month_number
local month_name
+
local month_name
local categories = {}
+
local categories = {}
local link = ''
+
local link = ''
local category = ''
+
local category = ''
local sortdate = ''
+
local sortdate = ''
local output = ''
+
local output = ''
  +
 
month_number = p.get_month_number({month}) or '01'
+
month_number = p.get_month_number({month}) or '01'
month_name = p.get_month_name({month}) or ''
+
month_name = p.get_month_name({month}) or ''
   
if h.isempty(year)
+
if h.isempty(year)
then year = ''
+
then year = ''
end
+
end
  +
 
if year ~= ''
+
if year ~= ''
then
+
then
sortdate = year..month_number..'01'
+
sortdate = year..month_number..'01'
--published = p.lua_date_comparison(sortdate)
+
--published = p.lua_date_comparison(sortdate)
sortdate = '&nbsp;'..sortdate
+
sortdate = '&nbsp;'..sortdate
link, category = p.lua_get_publication_category(year, month_name)
+
link, category = p.lua_get_publication_category(year, month_name)
table.insert(categories, year)
+
table.insert(categories, year)
table.insert(categories, category)
+
table.insert(categories, category)
table.insert(categories, p.get_era({year}))
+
--table.insert(categories, p.get_era({year}))
elseif not h.isempty(canceled) and not canceled
+
elseif not h.isempty(canceled) and not canceled
then table.insert(categories, 'Need Comic Dates')
+
then table.insert(categories, 'Need Comic Dates')
end
+
end
output = {
+
output = {
link = link,
+
link = link,
year = year,
+
year = year,
month = month_name,
+
month = month_name,
sortdate = sortdate,
+
sortdate = sortdate,
--published = published,
+
--published = published,
  +
}
}
 
  +
 
return output, categories
+
return output, categories
 
end
 
end
   
  +
-----------------------------------------------------------------------
 
  +
--------------------------------------------------------------------------------
 
--check if comics, episode, movie, etc. was recently released/published
 
--check if comics, episode, movie, etc. was recently released/published
 
function p.isRecent(frame)
 
function p.isRecent(frame)
local args = getArgs(frame)
+
local args = getArgs(frame)
local release_date = args['releasedate']
+
local release_date = args['releasedate']
local year = args['year']
+
local year = args['year']
local month = args['month']
+
local month = args['month']
local canceled = args['canceled'] or false
+
local canceled = args['canceled'] or false
local output = false
+
local output = false
   
if not canceled and (p.lua_is_recently_published(year, month) or p.lua_is_recently_released(release_date))
+
if not canceled and (p.lua_is_recently_published(year, month) or p.lua_is_recently_released(release_date))
then output = true
+
then output = true
end
+
end
  +
 
return output
+
return output
 
end
 
end
   
  +
  +
--------------------------------------------------------------------------------
 
function p.lua_is_recently_published(year, month)
 
function p.lua_is_recently_published(year, month)
local current_date = p.lua_date_converter()
+
local current_date = p.lua_date_converter()
local s
+
local s
local publication_date
+
local publication_date
local output = false
+
local output = false
  +
 
if not h.isempty(year)
+
if not h.isempty(year)
then
+
then
month = p.get_month_number({month}) or '01'
+
month = p.get_month_number({month}) or '01'
publication_date = year..month..'01'
+
publication_date = year..month..'01'
s = language:formatDate('Ym', '-2 months')..'01'
+
s = language:formatDate('Ym', '-2 months')..'01'
if publication_date>=s and publication_date<=current_date
+
if publication_date>=s and publication_date<=current_date
then output = true
+
then output = true
  +
end
end
 
end
+
end
   
return output
+
return output
 
end
 
end
   
   
  +
--------------------------------------------------------------------------------
 
function p.lua_is_recently_released(release_date)
 
function p.lua_is_recently_released(release_date)
local today = p.lua_date_converter('now', 'Ymd')
+
local today = p.lua_date_converter('now', 'Ymd')
local output = false
+
local output = false
  +
 
if not h.isempty(release_date)
+
if not h.isempty(release_date)
then
+
then
release_date = p.lua_date_converter(release_date, 'Ymd')
+
release_date = p.lua_date_converter(release_date, 'Ymd')
if release_date<=today and
+
if release_date<=today and
release_date>=language:formatDate('Ymd', '-4 months')
+
release_date>=language:formatDate('Ymd', '-4 months')
then output = true
+
then output = true
  +
end
end
 
end
+
end
   
return output
+
return output
 
end
 
end
   
   
-----------------------------------------------------------------------
+
--------------------------------------------------------------------------------
  +
function p.lua_is_recently_released_episode(year, month, day)
  +
local release_date
  +
local today = p.lua_date_converter('now', 'Ymd')
  +
local output = false
  +
  +
if not h.isempty(year) and not h.isempty(month) and not h.isempty(day)
  +
then
  +
month = p.get_month_number({month})
  +
day = string.rep( '0', 2-#tostring(day) )..day
  +
release_date = year..month..day
  +
if release_date<=today and release_date>=language:formatDate('Ymd', '-2 weeks')
  +
then output = true
  +
end
  +
end
  +
  +
return output
  +
end
  +
  +
--*************************************************************************************************
 
-- functions to manually calculate number of week (based on date) or date (based on number of week)
 
-- functions to manually calculate number of week (based on date) or date (based on number of week)
   
  +
--------------------------------------------------------------------------------
  +
-- return week number and year from "Week WW, YYYY" format
  +
function p.lua_get_week_number_and_year_from_week_name(week_name)
  +
local week_number
  +
local year
  +
  +
week_number, year = string.match(week_name, 'Week (%d+), (%d%d%d%d)')
  +
  +
return tonumber(week_number), tonumber(year)
  +
end
  +
  +
  +
--------------------------------------------------------------------------------
  +
function p.lua_get_week_name_from_week_number_and_year(week_number, year)
  +
local output = ''
  +
  +
if not h.isempty(week_number) and not h.isempty(year)
  +
then
  +
if #tostring(week_number) == 1
  +
then week_number = '0'..week_number
  +
end
  +
output = 'Week '..week_number..', '..year
  +
end
  +
  +
return output
  +
end
  +
  +
  +
--------------------------------------------------------------------------------
 
function p.lua_is_leap_year(year)
 
function p.lua_is_leap_year(year)
local output = false
+
local output = false
if math.fmod( year-1904, 4 ) == 0
+
if math.fmod( year-1904, 4 ) == 0
then output = true
+
then output = true
end
+
end
  +
 
return output
+
return output
 
end
 
end
   
   
  +
--------------------------------------------------------------------------------
function p.lua_get_day_number_of_year(year, month, day)
 
  +
function p.lua_get_day_of_year(year, month, day)
local output = day
 
  +
local output = day
   
for i = 1, month-1 do
+
for i = 1, month-1 do
output = output + days_in_month[i]
+
output = output + days_in_month[i]
end
+
end
   
if p.lua_is_leap_year(year) and month > 2
+
if p.lua_is_leap_year(year) and month > 2
then output = output + 1
+
then output = output + 1
end
+
end
   
return output
+
return output
 
end
 
end
   
  +
  +
--------------------------------------------------------------------------------
  +
function p.lua_get_date_from_day_of_year(day_of_year, year)
  +
local i = 1
  +
local j
  +
local leap_year = p.lua_is_leap_year(year)
  +
local output
  +
  +
if day_of_year > 366 and leap_year
  +
then
  +
day_of_year = day_of_year - 366
  +
year = year + 1
  +
elseif day_of_year > 365 and not leap_year
  +
then
  +
day_of_year = day_of_year - 365
  +
year = year + 1
  +
elseif day_of_year < 0
  +
then
  +
year = year - 1
  +
leap_year = p.lua_is_leap_year(year)
  +
if leap_year
  +
then day_of_year = day_of_year + 366
  +
else day_of_year = day_of_year + 365
  +
end
  +
end
  +
  +
if day_of_year == 0
  +
then output = 'December 31, '..year-1
  +
else
  +
output = day_of_year
  +
j = days_in_month[1]
  +
  +
while output > j do
  +
output = output - j
  +
i = i + 1
  +
if i == 2 and leap_year
  +
then j = 29
  +
else j = days_in_month[i]
  +
end
  +
end
  +
  +
output = p.get_month_name({i})..' '..output..', '..year
  +
end
  +
  +
return output
  +
end
  +
  +
  +
--------------------------------------------------------------------------------
 
-- return day of week for January 1 (1 = Monday, 7 = Sunday, etc.)
 
-- return day of week for January 1 (1 = Monday, 7 = Sunday, etc.)
 
-- day of week repeats every 28 years
 
-- day of week repeats every 28 years
function p.lua_get_first_day_of_year(year)
+
function p.lua_get_day_of_week_of_january_1(year)
local day_of_week_of_january_1 = {5,7,1,2,3,5,6,7,1,3,4,5,6,1,2,3,4,6,7,1,2,4,5,6,7,2,3,4}
+
local output = {5,7,1,2,3,5,6,7,1,3,4,5,6,1,2,3,4,6,7,1,2,4,5,6,7,2,3,4}
local year_number = math.fmod( year-1904, 28 ) + 1
+
local year_number = math.fmod( year-1904, 28 ) + 1
return day_of_week_of_january_1[year_number]
+
return output[year_number]
 
end
 
end
   
  +
  +
--------------------------------------------------------------------------------
 
-- return first day of the year's first week. If it started in december of the previous year, then negative number is returned (for example, first week of 2020 year started on December 30, 2019, so function returns -2)
 
-- return first day of the year's first week. If it started in december of the previous year, then negative number is returned (for example, first week of 2020 year started on December 30, 2019, so function returns -2)
 
function p.lua_get_first_day_of_first_week_of_year(year)
 
function p.lua_get_first_day_of_first_week_of_year(year)
local first_day = p.lua_get_first_day_of_year(year)
+
local first_day = p.lua_get_day_of_week_of_january_1(year)
return math.fmod( 11-first_day, 7) - 3
+
return math.fmod( 11-first_day, 7) - 3
 
end
 
end
   
   
  +
--------------------------------------------------------------------------------
 
function p.lua_get_day_of_week(year, month, day)
 
function p.lua_get_day_of_week(year, month, day)
local first_day = p.lua_get_first_day_of_year(year)
+
local first_day = p.lua_get_day_of_week_of_january_1(year)
local day_number = p.lua_get_day_number_of_year(year, month, day)
+
local day_of_year = p.lua_get_day_of_year(year, month, day)
local output
+
local output
   
output = math.fmod(first_day + day_number - 1, 7 )
+
output = math.fmod(first_day + day_of_year - 1, 7 )
if output == 0
+
if output == 0
then output = 7
+
then output = 7
end
+
end
  +
 
return output
+
return output
 
end
 
end
   
   
  +
--------------------------------------------------------------------------------
 
function p.lua_get_week_number(year, month, day)
 
function p.lua_get_week_number(year, month, day)
local function get_week_number(year, month, day)
+
local day_of_year = p.lua_get_day_of_year(year, month, day)
local first_day = p.lua_get_first_day_of_year(year)
+
local day_of_week = p.lua_get_day_of_week(year, month, day)
  +
local week_number = math.floor( (day_of_year - day_of_week + 10) / 7 )
local day_number = p.lua_get_day_number_of_year(year, month, day)
 
  +
local output
local first_day_of_first_week = p.lua_get_first_day_of_first_week_of_year(year)
 
  +
return math.floor( (day_number - first_day_of_first_week - 1) / 7 ) + 1
 
  +
if week_number == 0
end
 
  +
then
 
  +
year = year - 1
local output = get_week_number(year, month, day)
 
  +
week_number = p.lua_get_last_week_of_year2(year)
 
  +
elseif week_number == 53 and p.lua_get_last_week_of_year2(year) == 52
if output == 0
 
  +
then
then output = get_week_number(year - 1, 12, 31)
 
  +
year = year + 1
end
 
  +
week_number = 1
 
  +
end
return output
 
  +
  +
output = p.lua_get_week_name_from_week_number_and_year(week_number, year)
  +
  +
return output
 
end
 
end
   
   
  +
--------------------------------------------------------------------------------
 
-- return date of Wednesday for "year"'s week
 
-- return date of Wednesday for "year"'s week
 
function p.lua_get_date_from_week_number(week_number, year)
 
function p.lua_get_date_from_week_number(week_number, year)
local first_day_of_first_week = p.lua_get_first_day_of_first_week_of_year(year)
+
local first_day_of_first_week
local i = 1
+
local i = 1
local leap_year = p.lua_is_leap_year(year)
+
local leap_year
local first_day = p.lua_get_first_day_of_year(year)
+
local first_day
  +
local last_week = p.lua_get_last_week_of_year2(year)
local month
 
local output
+
local month
  +
local output
 
if week_number == 53 and not (
 
(leap_year and first_day == 3) or
 
(not leap_year and first_day == 4)
 
)
 
then return nil
 
end
 
   
  +
if week_number > last_week
output = first_day_of_first_week + 7 * (week_number-1) + 3
 
  +
then
month = days_in_month[i]
 
  +
week_number = week_number - last_week
while output > month do
 
  +
year = year + 1
output = output - month
 
  +
end
i = i + 1
 
  +
if i == 2 and leap_year
 
  +
first_day_of_first_week = p.lua_get_first_day_of_first_week_of_year(year)
then month = 29
 
  +
leap_year = p.lua_is_leap_year(year)
else month = days_in_month[i]
 
  +
first_day = p.lua_get_day_of_week_of_january_1(year)
end
 
end
 
   
  +
output = first_day_of_first_week + 7 * (week_number-1) + 3
output = p.get_month_name( { i } )..' '..output..', '..year
 
  +
output = p.lua_get_date_from_day_of_year(output, year)
   
return output
+
return output
 
end
 
end
   
   
  +
--------------------------------------------------------------------------------
function p.lua_last_week_of_year(year)
 
  +
function p.lua_get_last_week_of_year(year)
local leap_year = p.lua_is_leap_year(year)
 
  +
local function week_number(y)
local first_day = p.lua_get_first_day_of_year(year)
 
  +
local output = y + (y / 4) - (y / 100) + (y / 400)
local output = 52
 
  +
return math.floor( math.fmod(output, 7) )
 
  +
end
if ( (leap_year and first_day == 3) or (not leap_year and first_day == 4) )
 
  +
then output = 53
 
  +
if week_number(year) == 4 or week_number(year - 1) == 3
end
 
  +
then return 53
 
return output
+
else return 52
  +
end
 
end
 
end
   
  +
  +
--------------------------------------------------------------------------------
  +
function p.lua_get_last_week_of_year2(year)
  +
local first_day = p.lua_get_day_of_week_of_january_1(year)
  +
local last_day = p.lua_get_day_of_week(year, 12, 31)
  +
local leap_year = p.lua_is_leap_year(year)
  +
  +
if ( not leap_year and (first_day == 4 or last_day == 4) ) or ( leap_year and (first_day == 3 or last_day == 5) )
  +
then return 53
  +
else return 52
  +
end
  +
end
  +
--*************************************************************************************************
  +
  +
--------------------------------------------------------------------------------
 
function p.lua_get_previous_next_weeks(week_number, year)
 
function p.lua_get_previous_next_weeks(week_number, year)
local previous_week
+
local previous_week
local next_week
+
local next_week
  +
 
if week_number == 1
+
if week_number == 1
then previous_week = p.lua_last_week_of_year(year - 1)
+
then previous_week = p.lua_get_date_from_week_number(p.lua_get_last_week_of_year2(year - 1), year - 1)
else previous_week = p.lua_get_date_from_week_number(week_number - 1, year)
+
else previous_week = p.lua_get_date_from_week_number(week_number - 1, year)
end
+
end
  +
 
if week_number == p.lua_last_week_of_year(year)
+
if week_number == p.lua_get_last_week_of_year2(year)
then next_week = p.lua_get_date_from_week_number(1, year + 1)
+
then next_week = p.lua_get_date_from_week_number(1, year + 1)
else next_week = p.lua_get_date_from_week_number(week_number + 1, year)
+
else next_week = p.lua_get_date_from_week_number(week_number + 1, year)
end
+
end
  +
 
return previous_week, next_week
+
return previous_week, next_week
 
end
 
end
   
  +
  +
--------------------------------------------------------------------------------
  +
function p.get_previous_next_weeks(frame)
  +
local design = require("Module:Design")
  +
local current_date = p.lua_get_release_week_from_release_date( p.lua_date_converter() )
  +
local pagename = mw.title.getCurrentTitle().text
  +
local link
  +
local category = true
  +
local previous_week
  +
local next_week
  +
local output = ''
  +
  +
week_number, year = p.lua_get_week_number_and_year_from_week_name(pagename)
  +
if week_number == nil or year == nil
  +
then
  +
week_number, year = p.lua_get_week_number_and_year_from_week_name(current_date)
  +
category = false
  +
end
  +
  +
previous_week, next_week = p.lua_get_previous_next_weeks(week_number, year)
  +
  +
link = p.lua_get_release_week_from_release_date(previous_week)
  +
previous_week = h.LinkToCategory(link, previous_week)
  +
  +
link = p.lua_get_release_week_from_release_date(next_week)
  +
next_week = h.LinkToCategory(link, next_week)
  +
  +
pagename = p.lua_get_date_from_week_number(week_number, year)
  +
  +
output = design.messagebox({ previous_week..' &mdash; '..pagename..' &mdash; '..next_week })
  +
  +
if category
  +
then
  +
category = p.lua_get_date_from_week_number(week_number, year)
  +
category = string.gsub(category, ' %d+, ', ', ')
  +
category = 'Comics Released in '..category
  +
output = output..h.Category(category)
  +
end
  +
  +
return output
  +
end
  +
  +
  +
--------------------------------------------------------------------------------
  +
function p.lua_get_release_week_from_release_date(release_date)
  +
local year
  +
local month
  +
local day
  +
local output = ''
  +
  +
if not h.isempty(release_date)
  +
then
  +
release_date = p.lua_date_converter(release_date, 'F j, Y')
  +
month, day, year = string.match(release_date, '(.-) (%d-), (%d%d%d%d)')
  +
month = tonumber( p.get_month_number({month}) )
  +
output = p.lua_get_week_number(year, month, day)
  +
end
  +
  +
return output
  +
end
  +
  +
  +
--------------------------------------------------------------------------------
  +
-- used in Template:ReleaseWeek
  +
function p.get_release_week_from_release_date(frame)
  +
local args = getArgs(frame)
  +
local release_date = args[1]
  +
local output
  +
  +
if h.isempty(release_date)
  +
then output = p.lua_get_release_week_from_release_date( p.lua_date_converter() ) -- current date
  +
else output = p.lua_get_release_week_from_release_date(release_date)
  +
end
  +
  +
return output
  +
end
  +
  +
  +
--------------------------------------------------------------------------------
 
function p.lua_get_link_to_release_week(release_date, week_number, year)
 
function p.lua_get_link_to_release_week(release_date, week_number, year)
local month
+
local month
local day
+
local day
local output = ''
+
local output = ''
  +
 
if not h.isempty(release_date)
+
if not h.isempty(release_date)
then
+
then
release_date = p.lua_date_converter(release_date, 'F j, Y')
+
release_date = p.lua_date_converter(release_date, 'F j, Y')
  +
week_number = p.lua_get_release_week_from_release_date(release_date)
month, day, year = string.match(release_date, '(.-) (%d-), (%d%d%d%d)')
 
  +
output = h.LinkToCategory(week_number, release_date)
month = tonumber( p.get_month_number({month}) )
 
  +
elseif not h.isempty(week_number) and not h.isempty(year)
week_number = p.lua_get_week_number(year, month, day)
 
  +
then
if #tostring(week_number) == 1
 
  +
release_date = p.lua_get_date_from_week_number(week_number, year)
then week_number = '0'..week_number
 
  +
week_number = p.lua_get_week_name_from_week_number_and_year(week_number, year)
end
 
week_number = 'Week '..week_number..', '..year
+
output = h.LinkToCategory(week_number, release_date)
  +
end
output = h.lua_link_to_category(week_number, release_date)
 
  +
elseif not h.isempty(week_number) and not h.isempty(year)
 
  +
return output
then
 
  +
end
release_date = p.lua_get_date_from_week_number(week_number, year)
 
  +
if #tostring(week_number) == 1
 
  +
then week_number = '0'..week_number
 
  +
--------------------------------------------------------------------------------
end
 
  +
function p.lua_get_release_week_category(release_date)
week_number = 'Week '..week_number..', '..year
 
  +
local week
output = h.lua_link_to_category(week_number, release_date)
 
  +
local output = ''
end
 
  +
 
  +
week = p.lua_get_release_week_from_release_date(release_date)
return output
 
  +
if week ~= ''
  +
then output = h.Category(week)
  +
end
  +
  +
return output
  +
end
  +
  +
  +
--------------------------------------------------------------------------------
  +
-- used in Template:Month Category
  +
function p.get_previous_and_next_month(frame)
  +
local pagename = mw.title.getCurrentTitle().text
  +
local year
  +
local month
  +
local month_number
  +
local next_month
  +
local previous_month
  +
local design = require("Module:Design")
  +
local output = ''
  +
  +
year, month = string.match(pagename, '(%d+), (.+)')
  +
if year ~= nil and month ~= nil
  +
then
  +
year = tonumber(year)
  +
month_number = tonumber( p.get_month_number({month}) )
  +
if month_number == 1
  +
then
  +
previous_month = tostring(year - 1)..', December'
  +
next_month = tostring(year)..', February'
  +
elseif month_number == 12
  +
then
  +
previous_month = tostring(year)..', November'
  +
next_month = tostring(year+1)..', January'
  +
else
  +
previous_month = tostring(year)..', '..p.get_month_name({month_number-1})
  +
next_month = tostring(year)..', '..p.get_month_name({month_number+1})
  +
end
  +
  +
previous_month = h.LinkToCategory(previous_month, previous_month)
  +
next_month = h.LinkToCategory(next_month, next_month)
  +
  +
output = design.messagebox({previous_month..' — '..pagename..' — '..next_month})
  +
output = output..h.Category(year, year..' '..p.get_month_number({month}))
  +
end
  +
  +
return output
 
end
 
end
   

Revision as of 06:42, 28 August 2021

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

local p = {}
local monthData = mw.loadData( 'Module:Month/data' )
local h = require("Module:HF")
local getArgs = require('Dev:Arguments').getArgs
local language = mw.language.new('en')
local month_names = monthData[1]
local month_numbers = monthData[2]
local days_in_month = {31,28,31,30,31,30,31,31,30,31,30,31}

--------------------------------------------------------------------------------
-- return full month name
function p.get_month_name(frame)
	local args = getArgs(frame)
	local name = args[1]
	local output = nil
	
	if not h.isempty(name)
		then
			name = mw.text.trim(name)
			name = string.gsub(name, '^0', '')
			output = month_names[ string.lower(name) ]
	end

	return output
end


--------------------------------------------------------------------------------
-- return month number
function p.get_month_number(frame)
	local args = getArgs(frame)
	local number = args[1]
	local output = nil
	if not h.isempty(number)
		then
			number = mw.text.trim(number)
			number = string.gsub(number, '^0', '')
			output = month_numbers[ string.lower(number) ]
	end

	return output
end


--------------------------------------------------------------------------------
--takes a date and formats it according to the syntax - https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions##time
function p.lua_date_converter(s_date, s_format)
	local year = nil
	local month = nil
	local day = nil
	local i = 0
	local j = 0
	local output = ''
	
	s_format = s_format or 'Ymd'
	
	if h.isempty(s_date) or s_date == 'now'
		then output = language:formatDate(s_format)
		else
			month, day, year = string.match(s_date, '(.+) (.+), (%d%d%d%d)')
			if month == nil
				then month, day, year = string.match(s_date, '(.+)%-(.+)%-(%d%d%d%d)')
			end
			if day ~= nil and month ~= nil and year ~= nil
				then
					month = p.get_month_number({month})
					if #day == 1 then day = '0'..day end
					if s_format == 'Ymd'
						then output = year..month..day
						elseif s_format == 'Ym'
							 then output = year..month
						elseif s_format == 'F j, Y'
							then
								day = string.gsub(day, '^0', '')
								month = p.get_month_name({month})
								output = month..' '..day..', '..year
						else output = language:formatDate(s_format, month..' '..day..' '..year)
					end
				else output = language:formatDate(s_format, s_date)
			end
	end

	return output
end


--------------------------------------------------------------------------------
--compares two dates. Return "true" if 1st date is before the 2nd date, and "false" otherwise.
function p.lua_date_comparison(date1, date2)
	local output
	
	date1 = p.lua_date_converter(date1, 'Ymd')
	if tonumber( string.sub(date1, 1, 4) ) < 2020 
		and (   h.isempty(date2) 
				or date2 == 'now' 
				or tonumber( string.sub(p.lua_date_converter(date2, 'Ymd'), 1, 4) ) >= 2020
			)
		then output = true
		else
			date2 = p.lua_date_converter(date2 or 'now', 'Ymd') --If 2nd date is ommited, then current date is used for comparison.
			output = date1<=date2
	end
	
	return output
end


--------------------------------------------------------------------------------
--returns era based on year
--[[
function p.get_era(frame)
	local args = getArgs(frame)
	local year = tonumber(args[1])
	local key = args[2] or ''
	local output = ''

	if not h.isempty(year)
		then
			if not h.isempty(key) then key = ' '..key end
			if year<1955 then output = 'Golden-Age'..key end
			if year>=1955 and year<1970 then output = 'Silver-Age'..key end
			if year>=1970 and year<1983 then output = 'Bronze-Age'..key end
			if year>=1983 and year<1992 then output = 'Copper-Age'..key end
			if year>=1992 then output = 'Modern-Age'..key end
	end
	
	return output
end
]]--

--------------------------------------------------------------------------------
function p.lua_get_publication_category(year, month, day)
	local link = ''
	local category = ''
	local text = ''

	if not h.isempty(year)
		then
			month = p.get_month_name({month})
			if month ~= nil
				then 
					if h.isempty(day)
						then day = ''
						else day = ' '..day
					end
					category = year..', '..month
					link = h.LinkToCategory(category, month..day)..', '..h.LinkToCategory(year, year)
					text = month..', '..year
				else
					category = year
					link = h.LinkToCategory(year, year)
					text = year
			end
	end
	
	return link, category, text
end


--------------------------------------------------------------------------------
-- returns information about release date
function p.lua_get_release_date_info(release_date)
	local recent = false
	local releaseweek
	local text = ''
	local link = ''
	local year = ''
	local month = ''
	local day = ''
	local no_day = ''
	local category = ''
	local output = ''
	
	if not h.isempty(release_date)
		then 
			output = p.lua_date_converter(release_date, 'F j, Y')
			month, day, year = string.match(output, '(.-) (%d-), (%d%d%d%d)')
			no_day = month..', '..year
			link = p.lua_get_link_to_release_week(output)
			text = h.break_link(link, 1)
			recent = p.lua_is_recently_released(output)
	end

	output = {
		date = output, 
		week = {
			text = text, 
			link = link
		},
		recent = recent,
		day = day,
		month = month,
		year = year,
		no_day = no_day
	}

	return output
end


--------------------------------------------------------------------------------
-- returns information about publication date
function p.lua_get_publication_date_info(year, month, canceled)
	--local published = true
	local month_number
	local month_name
	local categories = {}
	local link = ''
	local category = ''
	local sortdate = ''
	local output = ''
	
	month_number = p.get_month_number({month}) or '01'
	month_name = p.get_month_name({month}) or ''

	if h.isempty(year)
		then year = ''
	end
	
	if year ~= ''
		then
			sortdate = year..month_number..'01'
			--published = p.lua_date_comparison(sortdate)
			sortdate = '&nbsp;'..sortdate
			link, category = p.lua_get_publication_category(year, month_name)
			table.insert(categories, year)
			table.insert(categories, category)
			--table.insert(categories, p.get_era({year}))
		elseif not h.isempty(canceled) and not canceled
			then table.insert(categories, 'Need Comic Dates')
	end
	output = {
		link = link, 
		year = year, 
		month = month_name, 
		sortdate = sortdate,
		--published = published,
	}
	
	return output, categories
end


--------------------------------------------------------------------------------
--check if comics, episode, movie, etc. was recently released/published
function p.isRecent(frame)
	local args = getArgs(frame)
	local release_date = args['releasedate']
	local year = args['year']
	local month = args['month']
	local canceled = args['canceled'] or false
	local output = false

	if not canceled and (p.lua_is_recently_published(year, month) or p.lua_is_recently_released(release_date))
		then output = true
	end
	
	return output
end


--------------------------------------------------------------------------------
function p.lua_is_recently_published(year, month)
	local current_date = p.lua_date_converter()
	local s
	local publication_date
	local output = false
	
	if not h.isempty(year)
		then
			month = p.get_month_number({month}) or '01'
			publication_date = year..month..'01'
			s = language:formatDate('Ym', '-2 months')..'01'
			if publication_date>=s and publication_date<=current_date
				then output = true
			end
	end

	return output
end


--------------------------------------------------------------------------------
function p.lua_is_recently_released(release_date)
	local today = p.lua_date_converter('now', 'Ymd')
	local output = false
	
	if not h.isempty(release_date)
		then
			release_date = p.lua_date_converter(release_date, 'Ymd')
			if release_date<=today and 
			   release_date>=language:formatDate('Ymd', '-4 months') 
				then output = true
			end
	end

	return output
end


--------------------------------------------------------------------------------
function p.lua_is_recently_released_episode(year, month, day)
	local release_date
	local today = p.lua_date_converter('now', 'Ymd')
	local output = false
	
	if not h.isempty(year) and not h.isempty(month) and not h.isempty(day)
		then
			month = p.get_month_number({month})
			day = string.rep( '0', 2-#tostring(day) )..day
			release_date = year..month..day
			if release_date<=today and release_date>=language:formatDate('Ymd', '-2 weeks') 
				then output = true
			end
	end

	return output
end

--*************************************************************************************************
-- functions to manually calculate number of week (based on date) or date (based on number of week)

--------------------------------------------------------------------------------
-- return week number and year from "Week WW, YYYY" format
function p.lua_get_week_number_and_year_from_week_name(week_name)
	local week_number
	local year
	
	week_number, year = string.match(week_name, 'Week (%d+), (%d%d%d%d)')
	
	return tonumber(week_number), tonumber(year)
end


--------------------------------------------------------------------------------
function p.lua_get_week_name_from_week_number_and_year(week_number, year)
	local output = ''
	
	if not h.isempty(week_number) and not h.isempty(year)
		then 
			if #tostring(week_number) == 1
				then week_number = '0'..week_number
			end
			output = 'Week '..week_number..', '..year
	end
	
	return output
end


--------------------------------------------------------------------------------
function p.lua_is_leap_year(year)
	local output = false
	if math.fmod( year-1904, 4 ) == 0
		then output = true
	end
	
	return output
end


--------------------------------------------------------------------------------
function p.lua_get_day_of_year(year, month, day)
	local output = day

	for i = 1, month-1 do
		output = output + days_in_month[i]
	end

	if p.lua_is_leap_year(year) and month > 2
		then output = output + 1
	end

	return output
end


--------------------------------------------------------------------------------
function p.lua_get_date_from_day_of_year(day_of_year, year)
	local i = 1
	local j
	local leap_year = p.lua_is_leap_year(year)
	local output

	if day_of_year > 366 and leap_year
		then 
			day_of_year = day_of_year - 366
			year = year + 1
		elseif day_of_year > 365 and not leap_year
			then
				day_of_year = day_of_year - 365
				year = year + 1
		elseif day_of_year < 0
			then
				year = year - 1
				leap_year = p.lua_is_leap_year(year)
				if leap_year
					then day_of_year = day_of_year + 366
					else day_of_year = day_of_year + 365
				end
	end
	
	if day_of_year == 0
		then output = 'December 31, '..year-1
		else 
			output = day_of_year
			j = days_in_month[1]

			while output > j do
				output = output - j
				i = i + 1
				if i == 2 and leap_year
					then j = 29
					else j = days_in_month[i]
				end
			end

			output = p.get_month_name({i})..' '..output..', '..year
	end
	
	return output
end


--------------------------------------------------------------------------------
-- return day of week for January 1 (1 = Monday, 7 = Sunday, etc.)
-- day of week repeats every 28 years
function p.lua_get_day_of_week_of_january_1(year)
	local output = {5,7,1,2,3,5,6,7,1,3,4,5,6,1,2,3,4,6,7,1,2,4,5,6,7,2,3,4}
	local year_number = math.fmod( year-1904, 28 ) + 1
	return output[year_number]
end   


--------------------------------------------------------------------------------
-- return first day of the year's first week. If it started in december of the previous year, then negative number is returned (for example, first week of 2020 year started on December 30, 2019, so function returns -2)
function p.lua_get_first_day_of_first_week_of_year(year)
	local first_day = p.lua_get_day_of_week_of_january_1(year)
	return math.fmod( 11-first_day, 7) - 3
end


--------------------------------------------------------------------------------
function p.lua_get_day_of_week(year, month, day)
	local first_day = p.lua_get_day_of_week_of_january_1(year)
	local day_of_year = p.lua_get_day_of_year(year, month, day)
	local output

	output = math.fmod(first_day + day_of_year - 1, 7 )
	if output == 0
		then output = 7
	end
	
	return output
end


--------------------------------------------------------------------------------
function p.lua_get_week_number(year, month, day)
	local day_of_year = p.lua_get_day_of_year(year, month, day)
	local day_of_week = p.lua_get_day_of_week(year, month, day)
	local week_number = math.floor( (day_of_year - day_of_week + 10) / 7 )
	local output

	if week_number == 0
		then 
			year = year - 1
			week_number = p.lua_get_last_week_of_year2(year)
		elseif week_number == 53 and p.lua_get_last_week_of_year2(year) == 52
			then 
				year = year + 1
				week_number = 1
	end
	
	output = p.lua_get_week_name_from_week_number_and_year(week_number, year)
	
	return output
end


--------------------------------------------------------------------------------
-- return date of Wednesday for "year"'s week
function p.lua_get_date_from_week_number(week_number, year)
	local first_day_of_first_week
	local i = 1
	local leap_year
	local first_day
	local last_week = p.lua_get_last_week_of_year2(year)
	local month
	local output

	if week_number > last_week
		then
			week_number = week_number - last_week
			year = year + 1
	end
	
	first_day_of_first_week = p.lua_get_first_day_of_first_week_of_year(year)
	leap_year = p.lua_is_leap_year(year)
	first_day = p.lua_get_day_of_week_of_january_1(year)

	output = first_day_of_first_week + 7 * (week_number-1) + 3
	output = p.lua_get_date_from_day_of_year(output, year)

	return output
end


--------------------------------------------------------------------------------
function p.lua_get_last_week_of_year(year)
	local function week_number(y)
		local output = y + (y / 4) - (y / 100) + (y / 400)
		return math.floor( math.fmod(output, 7) )
	end

	if week_number(year) == 4 or week_number(year - 1) == 3
		then return 53
		else return 52
	end
end


--------------------------------------------------------------------------------
function p.lua_get_last_week_of_year2(year)
	local first_day = p.lua_get_day_of_week_of_january_1(year)
	local last_day = p.lua_get_day_of_week(year, 12, 31)
	local leap_year = p.lua_is_leap_year(year)
	
	if ( not leap_year and (first_day == 4 or last_day == 4) ) or ( leap_year and (first_day == 3 or last_day == 5) )
		then return 53
		else return 52
	end
end
--*************************************************************************************************

--------------------------------------------------------------------------------
function p.lua_get_previous_next_weeks(week_number, year)
	local previous_week
	local next_week

	if week_number == 1
		then previous_week = p.lua_get_date_from_week_number(p.lua_get_last_week_of_year2(year - 1), year - 1)
		else previous_week = p.lua_get_date_from_week_number(week_number - 1, year)
	end

	if week_number == p.lua_get_last_week_of_year2(year)
		then next_week = p.lua_get_date_from_week_number(1, year + 1)
		else next_week = p.lua_get_date_from_week_number(week_number + 1, year)
	end

	return previous_week, next_week
end


--------------------------------------------------------------------------------
function p.get_previous_next_weeks(frame)
	local design = require("Module:Design")
	local current_date = p.lua_get_release_week_from_release_date( p.lua_date_converter() ) 
	local pagename = mw.title.getCurrentTitle().text
	local link
	local category = true
	local previous_week
	local next_week
	local output = ''
	
	week_number, year = p.lua_get_week_number_and_year_from_week_name(pagename)
	if week_number == nil or year == nil
		then
			week_number, year = p.lua_get_week_number_and_year_from_week_name(current_date)
			category = false
	end
			
	previous_week, next_week = p.lua_get_previous_next_weeks(week_number, year)
			
	link = p.lua_get_release_week_from_release_date(previous_week)
	previous_week = h.LinkToCategory(link, previous_week)

	link = p.lua_get_release_week_from_release_date(next_week)
	next_week = h.LinkToCategory(link, next_week)
			
	pagename = p.lua_get_date_from_week_number(week_number, year)

	output = design.messagebox({ previous_week..'  &mdash;  '..pagename..'  &mdash;  '..next_week })
			
	if category
		then
			category = p.lua_get_date_from_week_number(week_number, year)
			category = string.gsub(category, ' %d+, ', ', ')
			category = 'Comics Released in '..category
			output = output..h.Category(category)
	end
	
	return output
end


--------------------------------------------------------------------------------
function p.lua_get_release_week_from_release_date(release_date)
	local year
	local month
	local day
	local output = ''

	if not h.isempty(release_date)
		then
			release_date = p.lua_date_converter(release_date, 'F j, Y')
			month, day, year = string.match(release_date, '(.-) (%d-), (%d%d%d%d)')
			month = tonumber( p.get_month_number({month}) )
			output = p.lua_get_week_number(year, month, day)
	end
	
	return output
end	


--------------------------------------------------------------------------------
-- used in Template:ReleaseWeek
function p.get_release_week_from_release_date(frame)
	local args = getArgs(frame)
	local release_date = args[1]
	local output
	
	if h.isempty(release_date)
		then output = p.lua_get_release_week_from_release_date( p.lua_date_converter() )  -- current date
		else output = p.lua_get_release_week_from_release_date(release_date)
	end
	
	return output
end
	

--------------------------------------------------------------------------------
function p.lua_get_link_to_release_week(release_date, week_number, year)
	local month
	local day
	local output = ''
	
	if not h.isempty(release_date)
		then
			release_date = p.lua_date_converter(release_date, 'F j, Y')
			week_number = p.lua_get_release_week_from_release_date(release_date)
			output = h.LinkToCategory(week_number, release_date)
		elseif not h.isempty(week_number) and not h.isempty(year)
			then
				release_date = p.lua_get_date_from_week_number(week_number, year)
				week_number = p.lua_get_week_name_from_week_number_and_year(week_number, year)
				output = h.LinkToCategory(week_number, release_date)
	end
	
	return output
end


--------------------------------------------------------------------------------
function p.lua_get_release_week_category(release_date)
	local week
	local output = ''
	
	week = p.lua_get_release_week_from_release_date(release_date)
	if week ~= ''
		then output = h.Category(week)
	end
	
	return output
end


--------------------------------------------------------------------------------
-- used in Template:Month Category
function p.get_previous_and_next_month(frame)
	local pagename = mw.title.getCurrentTitle().text
	local year
	local month
	local month_number
	local next_month
	local previous_month
	local design = require("Module:Design")
	local output = ''
	
	year, month = string.match(pagename, '(%d+), (.+)')
	if year ~= nil and month ~= nil
		then
			year = tonumber(year)
			month_number = tonumber( p.get_month_number({month}) )
			if month_number == 1
				then
					previous_month = tostring(year - 1)..', December'
					next_month = tostring(year)..', February'
				elseif month_number == 12
					then
						previous_month = tostring(year)..', November'
						next_month = tostring(year+1)..', January'
				else
					previous_month = tostring(year)..', '..p.get_month_name({month_number-1})
					next_month = tostring(year)..', '..p.get_month_name({month_number+1})
			end
	
			previous_month = h.LinkToCategory(previous_month, previous_month)
			next_month = h.LinkToCategory(next_month, next_month)
	
			output = design.messagebox({previous_month..' — '..pagename..' — '..next_month})
			output = output..h.Category(year, year..' '..p.get_month_number({month}))
	end
	
	return output
end

return p