Template:Date: Difference between revisions

From Drunkapedia
Jump to: navigation, search
imported>Tlosk
(New page: <includeonly>{{#switch:none |{{#iferror: {{#time:Y_M_d|{{{1|}}} }} | none }} <!-- #time: can't handle --> |{{#iferror: {{#expr: {{{1|}}}+0 }} |<!--not a pure number--> |{{#ifexpr...)
 
imported>Tlosk
No edit summary
Line 1: Line 1:
<includeonly>{{#switch:none
<includeonly></includeonly><noinclude>
|{{#iferror: {{#time:Y_M_d|{{{1|}}} }} | none }} <!-- #time: can't handle -->
|{{#iferror: {{#expr: {{{1|}}}+0 }}
    |<!--not a pure number-->
    |{{#ifexpr: {{{1|}}}+0 > 10000000000000
      |<!-- a yyyymmddhhmmss timestamp -->
      |{{#ifeq: {{#expr:{{{1|}}}+0}} | {{{1|}}}
          | none <!-- pure number eg 123.456 -->
          | <!-- assume yy-mm-dd -->
        }}
    }}
  }}
|{{#switch:  {{lc:{{{2|}}}}} | none | asis=none }}
|{{#ifexpr:  {{#time:Y|{{{1|}}} }} < 1000 | none }}
|{{#switch:  {{#time:Ynj|{{{1|}}} }}|100031|110031|130031|140031|150031=none}}
|= {{{1|}}}<!-- error or "none", so no formatting -->
|<!-- continue with formatting -->
  {{#ifeq:<!--
    -->{{#time:Y|{{{1}}} 2008}}<!--
    -->{{#iferror: {{#ifexpr: {{{1}}}>10000000000000 | no }} | }}<!--
    -->{{#time:Y|{{{1}}} 2004}}
  |20082004
  |<!-- no year -->
    {{#ifeq:{{#time:d|{{{1}}} 2036}}|{{#time:d|{{{1}}} }}
    |<!-- month+day -->{{#time:
      {{#switch: {{lc: {{#ifeq:{{{3|}}}|y|L}}{{{2|}}} }}
      | lmdy | liso | lymd      = [[:F j]]
      | mdy  | iso  | ymd      = F j
      | ldmy | l                = [[:j F]]
      | #default                = j F
      }}|{{{1}}} 2000 }}<!-- default='dmy' or null or "" or unsupported option -->
    |<!-- month only -->{{#time:
      {{#switch: {{lc: {{#ifeq:{{{3|}}}|y|L}}{{{2|}}} }}
      | lmdy | liso | lymd
      | ldmy | l                = [[F]]
      | #default                = F
      }}|{{{1}}} 2000 }}<!-- default='dmy'/'mdy'/'ymd'/'iso'/null/""/unsupported opt -->
    }}
  |<!-- with year-->
    {{#if: {{#iferror:{{#time:j|2 {{{1|}}}}}|*D*|{{#iferror:{{#time:j|2000 {{{1|}}}}}|*D*| }}}}
    |<!-- day+month+year -->{{#time:
      {{#switch: {{lc: {{#ifeq:{{{3|}}}|y|L}}{{{2|}}} }}
      | lmdy                    = [[:F j]], [[Y]]
      | mdy                    = F j, Y
      | liso                    = [[Y|Y-]][[F j|m-d]]<!-- i.e. [[Y-m-d]] -->
      | iso                    = Y-m-d
      | lymd                    = [[Y]] [[:F j]]
      | ymd                    = Y F j
      | ldmy | l                = [[:j F]] [[Y]]
      | #default                = j F Y
      }}|{{{1|}}} }}<!-- #default='dmy' or null or "" or unsupported option -->
    |<!-- month+year -->{{#time:
      {{#switch: {{lc: {{#ifeq:{{{3|}}}|y|L}}{{{2|}}} }}
      | lmdy | liso | lymd | ldmy | l  = [[:F Y]]
      | #default                = F Y
      }}|{{{1|}}} }}<!-- default='dmy'/'iso'/'mdy'/null/""/unsupported option -->
    }}
  }}   
}}</includeonly><noinclude>
== Syntax ==
== Syntax ==
This template takes up to two parameters, both of which are optional:
This template takes up to two parameters, both of which are optional:

Revision as of 17:55, 6 March 2009

Syntax

This template takes up to two parameters, both of which are optional:

{{date|<date to be formatted>|<date formatting style>}}

  • <date to be formatted> is an (optional) date to be formatted.
    If no date is specified, the template emits the current date.
    For example, {{date}} produces .
    If a date is provided, but is not recognized as one, the text is just returned as is. Most dates will however be recognized as such, including all the formats typically used on Wikipedia. Numerous variations thereof are also supported, including abbreviated or lower case month names; genitive 'st', 'nd', 'rd', 'th'; extraneous white space; missing comma etc.
    Notes:
    • Some dates are converted even if they are not real dates, and some dates are not converted even though they are real dates. See known issues below.
    • Only dates within the range and are supported. Dates with two digit dates will have unexpected results. Other dates outside the range 1000–9999 will be treated as if the second parameter were "none".
  • <date formatting style> controls the date format in which the result is to be emitted.
    If no style is specified, the template emits a date in 'd month yyyy' format, as it appears (for example) on discussion pages.
    Recognized values for the second parameter are:
    • none applies no formatting whatsoever
    • dmy gives d mmmm yyyy (eg '). This is the default format.
    • mdy gives mmmm d, yyyy (eg ')
    • ymd gives yyyy mmmm dd (eg ')
    • iso gives an ISO 8601 yyyy-mm-dd (eg ')
    Prefixing these parameters with "l" (l for link) produces a linked date:
    • ldmy gives [[d mmmm]] [[yyyy]] (eg ')
    • lmdy gives [[mmmm d]], [[yyyy]] (eg ')
    • lymd gives [[yyyy]] [[mmmm dd]] (eg ')
    • liso gives [[yyyy]]-[[mm-dd]] (eg ')
    Notes:
    • Although these are the four formats supported by MediaWiki's date autoformatting mechanism, only dmy/ldmy and mdy/lmdy are in accordance with the English language Wikipedia's Manual of Style. The use of iso/liso (ISO 8601) format within article prose is expressly discouraged by the Manual of Style; this format should only be used in tables or lists.
    • In each case, the result is exactly the same as what would be emitted by MediaWiki's date autoformatting mechanism.
      However, dates are not manipulated by MediaWiki's date autoformatting mechanism even when linked. This permits dates to have a consistent appearance regardless of whether they are linked or not.

Examples

Input Output
No format specified
{{date|2006-05-04}}
{{date|May 4, 2006}}
{{date|4 May 2006}}
{{date|4 May}}
{{date|May 4}}
dmy format
{{date|2006-05-04|dmy}}
{{date|May 4, 2006|dmy}}
{{date|4 May 2006|dmy}}
{{date|4 May|dmy}}
{{date|May 4|dmy}}
mdy format
{{date|2006-05-04|mdy}}
{{date|May 4, 2006|mdy}}
{{date|4 May 2006|mdy}}
{{date|4 May|mdy}}
{{date|May 4|mdy}}
ymd format
{{date|2006-05-04|ymd}}
{{date|May 4, 2006|ymd}}
{{date|4 May 2006|ymd}}
{{date|4 May|ymd}}
{{date|May 4|ymd}}
iso format
{{date|2006-05-04|iso}}
{{date|May 4, 2006|iso}}
{{date|4 May 2006|iso}}
{{date|4 May|iso}}
{{date|May 4|iso}}
none format
{{date|2006-05-04|none}}
{{date|May 4, 2006|none}}
{{date|4 May 2006|none}}
{{date|4 May|none}}
{{date|May 4|none}}