Difference between revisions of "Template:ISO date"

From blackwiki
Jump to navigation Jump to search
imported>Pigsonthewing
(add classes for use in templates emitting microformats - see WP:UF)
imported>Trödel
(if we pass a fake time in - it seems to still work and reduce the number of calls)
Line 1: Line 1:
 
<span class="bday dtstart updated"><!-- if formatted MMMM YYYY
 
<span class="bday dtstart updated"><!-- if formatted MMMM YYYY
  -->{{ #ifeq: {{{1|}}} | {{ #time: F Y | {{{1|}}} | local }}|<!--  
+
-->{{ #ifeq: {{{1|}}} | {{ #time: F Y | {{{1|}}} | local }}|<!--  
 
   then -->{{ #time: Y-m | {{{1|}}} | local }}|<!--
 
   then -->{{ #time: Y-m | {{{1|}}} | local }}|<!--
 
   else if formatted MMM YYYY
 
   else if formatted MMM YYYY
 
       -->{{ #ifeq: {{{1|}}} | {{ #time: M Y | {{{1|}}} | local }}|<!--  
 
       -->{{ #ifeq: {{{1|}}} | {{ #time: M Y | {{{1|}}} | local }}|<!--  
 
       then -->{{ #time: Y-m | {{{1|}}} | local }}|<!--
 
       then -->{{ #time: Y-m | {{{1|}}} | local }}|<!--
        else if formatted YYYY
+
      else if formatted YYYY
         -->{{ #ifeq: {{CURRENTYEAR}}-{{CURRENTMONTH}} |{{ #time: Y-m | {{{1|<noinclude>15 January 2001</noinclude>}}} | local }}|<!--  
+
         -->{{ #ifeq: {{{1|}}} | {{ #time: Y | 0:00 {{{1|<noinclude>15 January 2001</noinclude>}}} | local }}|<!--  
            then -->{{#if:{{{1|<noinclude>15 January 2001</noinclude>}}}|{{{1}}}|<span class="error">ISO date requires a parameter</span>}}|<!--  
+
        then -->{{#if:{{{1|<noinclude>15 January 2001</noinclude>}}}|{{{1}}}|<span class="error">ISO date requires a parameter</span>}}|<!--  
            else format general case as regular date
+
        else format general case as regular date
 
             -->{{ #time: Y-m-d |{{{1|<noinclude>15 January 2001</noinclude>}}}|local}}<!--
 
             -->{{ #time: Y-m-d |{{{1|<noinclude>15 January 2001</noinclude>}}}|local}}<!--
 
         end if-->}}<!--
 
         end if-->}}<!--

Revision as of 20:48, 12 November 2008

2001-01-15

This template converts dates to ISO dates (YYYY-MM-DD or YYYY-MM or YYYY as appropriate), see below for restrictions on input formats accepted.

Usage

The template may be used without any parameters, in which case it displays the current date: If no year has been specified, it displays the current year

  • {{ISO date|Aug 17}} returns 2026-08-17
  • {{ISO date}} returns 2026-01-14

The template accepts one unnamed parameter containing a date in one of the following formats:

  • {{ISO date|15 January 2001}} returns 2001-01-15
  • {{ISO date|15 Jan 2001}} returns 2001-01-15
  • {{ISO date|15-01-2001}} returns 2001-01-15
  • {{ISO date|January 15, 2001}} returns 2001-01-15
  • {{ISO date|Jan 15, 2001}} returns 2001-01-15
  • {{ISO date|Jan. 15, 2001}} returns 2001-01-15
  • {{ISO date|01/15/2001}} returns 2001-01-15
  • {{ISO date|January 2001}} returns 2001-01
  • {{ISO date|Jan 2001}} returns 2001-01
  • {{ISO date|2001}} returns 2001

Formats for which it can not work because #time returns an error or an incorrect ISO format:

  • {{ISO date|01-15-2001}} returns Error: Invalid time. (hyphens indicate DD-MM-YYYY and 15 is an invalid month number)
  • {{ISO date|15/01/2001}} returns Error: Invalid time. (slashes indicate MM/DD/YYYY and 15 is an invalid month number)
  • {{ISO date|1/2001}} returns Error: Invalid time.
  • {{ISO date|2001 January 15}} returns Error: Invalid time.
  • {{ISO date|2001 January}} returns 2001-01-01 (expected: 2001-01)

Use in microformats

Template:UF-date-part

See also