Wikimedia

[Lua task #11] Create a general date-handling function

Prerequisite: To work on this task, you MUST have knowledge of Lua programming already, or another language plus Lua tasks #01 to #09 here in Google Code-in. You will need to learn about Lua patterns (similar to regular expressions).

Wikipedia sometimes get dates written in unusual styles. There are four generally useful styles that we want to standardise on:

  • dmy format, e.g. 22 December 2017
  • mdy format, e.g. December 22, 2017
  • iso format, e.g. 2017-12-22
  • y format, e.g. 2017

They may be used in different contexts in Wikipedia, so a general date-handling function should accept a parameter to specify what output is required. e.g. |dateformat=dmy. Those are the four basic formats that we want the function to output, as selected by dateformat.

The input should be a piece of text that may contain a date. There are some examples at User:RexxS/DateDataTest.

You can add to those that dmy dates and mdy dates may have a suffix, which may be any of "AD", "BC", "CE", or "BCE". You'll need to have another input parameter that specifies either the AD/BC or CE/BCE styles for output.

1 Create a sandbox section that collects as many different types of test cases as you can think of.

2 Create a function that will accept arbitrary text and extract from it a likely date, then output it in the selected format.

3 Test your function with all of your cases. Give a link here.

Task tags

  • lua
  • scribunto

Students who completed this task

Tarun Prasad, Om Desai, Kid116

Task type

  • code Code
close

2017