Template:Year: Difference between revisions
Notjusttired (talk | contribs) m (redo from Wikipedia) |
Notjusttired (talk | contribs) (extract last word to see if 4 digits - if so use as year) |
||
Line 1: | Line 1: | ||
<includeonly>{{#if: {{{1|}}} | <includeonly>{{#ifeq:{{str len|{{digits|{{last word|{{{1|}}}}}}}}}|4 | ||
|{{digits|{{last word|{{{1|}}}}}}} | |||
|{{#if: {{{1|}}} | |||
|{{#iferror:{{#time:Y|1 January {{{1|}}} }} | |{{#iferror:{{#time:Y|1 January {{{1|}}} }} | ||
|{{#iferror:{{#time:Y|1st {{{1|}}} }} | |{{#iferror:{{#time:Y|1st {{{1|}}} }} | ||
Line 7: | Line 9: | ||
|{{#time:Y|1 {{{1|}}} }} }} | |{{#time:Y|1 {{{1|}}} }} }} | ||
|{{#time:Y|1 January {{{1|}}} }} }} | |{{#time:Y|1 January {{{1|}}} }} }} | ||
|{{CURRENTYEAR}}}}</includeonly><noinclude> | |{{CURRENTYEAR}}}}}}</includeonly><noinclude> | ||
{{Documentation}} | {{Documentation}} |
Latest revision as of 00:12, October 17, 2019
Uses Lua: |
New code: more time formats accepted[edit source]
If last "word" is 4 digits then just use that.
<!--ends in 4 digits --> {{#ifeq:{{str len|{{digits|{{last word|{{{1|}}}}}}}}}|4 |{{digits|{{last word|{{{1|}}}}}}} |false}}<!--doesnt end in 4 digits -->
April 26, 2024 → 2019
Apr 26, 2024 → 2019
Apr 2024 → 2019
Usage[edit source]
{{year|string formatted as a valid date}}
{{year|}} - 2024
{{year|1999}} - 1999
{{year|1999-12-12}} - 1999
{{year|January 1999}} - 1999
{{year|15 January 1999}} - 1999
{{year|January 1, 1999}} - 1999
{{year|1-2-1990}} - 1990
{{year|1/2/1990}} - 1990
{{year|2239-10-23}} - 2239
{{year|October 10, 2019}} 2019
{{year|Oct 2019}} 2019
{{year|Oct 10, 2019}} 2019
Reports "Error" without a reason if given bad input:
{{year|1-14-1990}} Error
Reason for the error: there are not 14 months.
{{year|61 January 1999}} 1999
Reason for the error: no month has 61 days.
{{year|1 MyMonth 1999}} 1999
Reason for the error: there is no such month name.
{{year|Some text which is not a date}} Error
Reason for the error: no date information to parse.
If used with a year range, it returns only the first match:
- {{year|1999-2001}} 1999
This presently only works when the year range is specified with a hyphen -; if correctly given with an en dash -; which looks very similar, it reports an error (handling ranges is not the template's function).
If used without input, it simply outputs the current year:
- {{year}} 2024
- {{year|}} 2024
It can be cleanly substituted for this purpose. If fed invalid data when substituted, it produces a larger, red error.
If used when the value is already a year rather than a full date, it simply outputs the year:
- {{year|2018}} 2018
See also[edit source]
- {{ISOdate}}
- {{ISOmonth}}
- {{ISOyear}}
- {{Day}}
- {{Date}}
- {{Month}}
- {{Year}}
- {{Time}}
- {{CURRENTYEAR}}
- {{Currentmonthday}}
- {{Currentmonthname}}
- {{Currentyear}}
- {{Complexdate}}
- {{Dated maintenance category}} (DMC)
- {{DMCA}}
- Module:I18n/date
- Magic word: CURRENTTIMESTAMP includes both date and time
{{date}}
– outputs the current date in various parameter-controlled formats{{DATE}}
– a subst-only convenience template used inside cleanup/dispute templates;|{{subst:DATE}}
produces:|date=December 2018
- Category:date and time templates – numerous date computing, formatting, annotating, and navigation templates
See also[edit source]
- {{ISOdate}}
- {{ISOmonth}}
- {{ISOyear}}
- {{Day}}
- {{Date}}
- {{Month}}
- {{Year}}
- {{Time}}
- {{CURRENTYEAR}}
- {{Currentmonthday}}
- {{Currentmonthname}}
- {{Currentyear}}
- {{Complexdate}}
- {{Dated maintenance category}} (DMC)
- {{DMCA}}
- Module:I18n/date
- Magic word: CURRENTTIMESTAMP includes both date and time
The above documentation is transcluded from Template:Year/doc. (edit | history) Editors can experiment in this template's sandbox (create | mirror) and testcases (create) pages. Please add categories to the /doc subpage. Subpages of this template. |