Template:Extract

From MEpedia, a crowd-sourced encyclopedia of ME and CFS science and history
template icon Template documentation[view] [edit] [history] [purge]

This template can extract information from a date, or can format a date. Time units can be added to a date.

Syntax[edit source]

  • {{extract|date|options}}

The following options are available:

  • add=periods to add • Add/subtract time units.
  • fix=on • Adjust invalid time units.
  • partial=on • Accept a year only, or a year and month only.
  • show=what to display • Specifies what should be extracted (such as dayname), or how to format the date (such as mdy).
  • sortable=on • A hidden sort key is inserted before the date (for use in sortable tables).

The date can be entered as the first parameter, or separate parameters can be used for the year/month/day/hour/minute/second components of a date.

By default, the date is displayed in dmy format, for example:

  • {{extract|2015-11-12}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).

Date[edit source]

A valid date must be specified. Dates are Coordinated Universal Time—local times and time zones are not supported.

Examples of valid dates follow. Each row shows two equivalent methods of entering a date.

A date as a single parameter Components of a date in separate parameters
{{extract|1900-02-01}} {{extract|1900|02|01}}
{{extract|1900-2-1 14:45}} {{extract|1900|2|1|14|45}}
{{extract|1 FEB 1900}} {{extract|1900|FEB|1}}
{{extract|February 1, 1900}} {{extract|1900|February|1}}
{{extract|Feb 1 1900 14:45}} {{extract|1900|Feb|1|14|45}}
{{extract|2:45 pm February 1 1900}} {{extract|1900|February|1|14|45}}
{{extract|1 February 1900 2:45 p.m.}} {{extract|1900|February|1|14|45}}
{{extract|BC 1 Feb 120}} {{extract|-119|2|1}}

The last example above uses the rule:

n BC is year 1 − n

Year 0 refers to 1 BC, and year −1 is 2 BC, etc.

Dates can also be entered with the following special names which are not case sensitive.

  • {{extract|currentdate}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string). (the date shown is when this documentation page was last purged)
  • {{extract|currentdatetime}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).

Add[edit source]

These time units can be added to a date:

  • y years
  • m months
  • d days
  • h hours
  • min minutes
  • s seconds

Multiple periods can be given, separated by spaces. There must be no space between a value and the code for the time unit.

A hyphen can be used for a negative value. Periods are added in the order given.

Examples:

  • {{extract|2004-04-03|add=28d}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|2004-04-03|add=3m 28d}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|2004-04-03|add=28d 3m}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string). (the order in which units are added changes the result)
  • {{extract|2004-04-03|add=-3d}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|2004-04-03|add=-912345d}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|2004-04-03|add=250h}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|2004-04-03|add=-2.5h}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|2004-04-30|add=-2m}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|2004-04-03|add=2y 3m 4d}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|2004-04-03|add=5.75d}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string). (years and months are integer only)

Fix[edit source]

By default, the date entered must be valid. If fix=on is used, units which are too large are "fixed". For example, 26 hours would be regarded as 1 day and 2 hours.

Entering a day as zero is regarded as the previous day (the last day of the previous month). The day before the previous day would be indicated with -1.

Similarly, entering a month as zero goes back one month, and entering -1 goes back two months.

Examples:

  • {{extract|2001|5|31|fix=on}}Lua error in Module:Date at line 78: attempt to index local 'datevec' (a string value). (no fix is required)
  • {{extract|2001|5|0|fix=on}}Lua error in Module:Date at line 78: attempt to index local 'datevec' (a string value).
  • {{extract|2001|5|-1|fix=on}}Lua error in Module:Date at line 78: attempt to index local 'datevec' (a string value).
  • {{extract|2001|125|-1000|fix=on}}Lua error in Module:Date at line 78: attempt to index local 'datevec' (a string value).
  • {{extract|2001|0|12|fix=on}}Lua error in Module:Date at line 78: attempt to index local 'datevec' (a string value).
  • {{extract|2016|3|0|fix=on}}Lua error in Module:Date at line 78: attempt to index local 'datevec' (a string value).

The following shows how to get the date for a given year and day-of-year. For example, June 30, 2001 is day 181 in the year 2001, as can be seen by adding 181 days to the date just before January 1, 2001.

  • {{extract|June 30, 2001|show=dayofyear}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string). (date to day-of-year)
  • {{extract|2001|1|0|fix=on|add=181d|show=mdy}}Lua error in Module:Date at line 78: attempt to index local 'datevec' (a string value). (day-of-year to date)

Partial[edit source]

If partial=on is used, the date may consist of a year only, or a year and month only. Addition is not supported for a partial date.

  • {{extract|2001|5|partial=on}}Lua error in Module:Date at line 78: attempt to index local 'datevec' (a string value).
  • {{extract|2016|partial=on|show=isleapyear}}Lua error in Module:Date at line 78: attempt to index local 'datevec' (a string value).

Show[edit source]

The following table lists most of the show parameters that can be used. Some of these work properly only with a full date.

Parameter Description
show=hide display nothing; may be useful with sortable=on
show=year year
show=month month (1 to 12)
show=day day of month (1 to 31)
show=hour hour (0 to 23)
show=minute minute (0 to 59)
show=second second (0 to 59)
show=dayabbr abbreviated name of day of week
show=dayname full name of day of week
show=dayofweek day-of-week (0=Sunday to 6=Saturday)
show=dayofweekiso day-of-week (1=Monday to 7=Sunday)
show=dayofyear day-of-year (1 to 366)
show=era an era code such as BC or BCE
show=format code for the detected format of the input date (dmy, mdy, ymd, or error)
show=gsd Gregorian serial date
show=juliandate Julian day
show=isleapyear 1 if the date is in a leap year; 0 otherwise
show=monthabbr abbreviated name of month
show=monthdays number of days in the month of the date
show=monthname full name of month
show=dmy show date as "day month year" (default)
show=mdy show date as "month day, year"
show=ymd show date as "year-month-day"

Examples:

  • {{extract|1 Feb 2001}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|FEB 1 2001}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|2001-2-1}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|1 Feb 2001|show=format}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|FEB 1 2001|show=format}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|2001-2-1|show=format}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|2001-2-29|show=format}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|1 Feb 2001|show=mdy}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|1 Feb 2001|show=ymd}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|June 30, 2001|show=dayname}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|June 30, 2001|show=dayofyear}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|2001-2-1|show=monthname}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|2001-2-1|show=a %{dayname} in %{monthname} }}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).

Some show options will not produce a useful result with a partial date, for example:

  • {{extract|2001|partial=on|show=juliandate}}Lua error in Module:Date at line 78: attempt to index local 'datevec' (a string value).
  • {{extract|2001|partial=on|show=monthname}}Lua error in Module:Date at line 78: attempt to index local 'datevec' (a string value).

Sortable[edit source]

The sort options are:

Parameter Description
prefix=text Insert the given text before the result but after any sort key.
sortable=off No sort key (default).
sortable=on Output a hidden sort key for use in sortable tables.
sortable=table Insert a sort key using table syntax data-sort-value="value"|.
sortable=debug Same as sortable=on but the sort key is displayed for testing.

The sort key is calculated from the juliandate value. For a partial date such as May 2016, the first day in the range is used (1 May 2016).

If wanted, show=hide can be used so the date is not displayed.

The prefix parameter allows the insertion of text that will not interfere with sorting. For example, {{extract|500 BC|prefix=c.|partial=on|sortable=on}} outputs a hidden sort key followed by "c. 500 BC".

Examples:

  • {{extract|1 Jan 2001|sortable=on}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|1 Jan 2001|sortable=on|show=hide}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|2300 BCE|partial=on|sortable=debug}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|1 Jan 2001|sortable=debug}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|1 Jan 2001|sortable=debug|show=hide}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).
  • {{extract|00:12 1 Jan 2001|sortable=debug|show=hide}}Lua error in ...ribunto/includes/engines/LuaCommon/lualib/mwInit.lua at line 23: bad argument #1 to 'old_ipairs' (table expected, got string).