Module:BucketDate

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:BucketDate/doc. [edit] [history] [purge]
Module:BucketDate's function main is invoked by Template:BucketReleaseDate.
Module:BucketDate's function main is invoked by Template:BucketRemovalDate.
Module:BucketDate is required by Module:Infobox.
Module:BucketDate is required by Module:Infobox/sandbox.
Function list
L 4 — p.main
L 10 — p._main

Used to parse the common infobox date wikicode format of [[27 February]] [[2002]], split it into its components, and then populate a target date Bucket. For examples, see Bucket:release_date or Bucket:removal_date.

Can be used directly (such as in modules) or via a template (such as {{BucketReleaseDate}} or {{BucketRemovalDate}}). The former should pass the target Bucket name as the third parameter, while the latter should add an invoke arg of bucket_name, e.g. {{#invoke:BucketDate|main|bucket_name=prom_date}}.


local p = {}
local lang = mw.getContentLanguage()

function p.main(frame)
	local bucket_name = frame.args.bucket_name
	local args = frame:getParent().args
	pcall(p._main, args[1], args.sub, bucket_name)
end

function p._main(date, page_name_sub, bucket_name)
	bucket_name = bucket_name or "release_date"
	if date == nil or date == '' then
		return
	end

	date = date:gsub('[[%]]', '')
	local bucketYear = lang:formatDate('Y', date)
	local bucketMonth = lang:formatDate('n', date)
	local bucketDay = lang:formatDate('j', date)
	bucket(bucket_name).sub(page_name_sub).put{
		date_text = date,
		date = os.time{year = bucketYear, month = lang:formatDate('m', date), day = bucketDay},
		year = bucketYear,
		month = bucketMonth,
		day = bucketDay,
	}
end

return p