Template:AgeFull: Difference between revisions

From OniGalore
Jump to navigation Jump to search
(existing code from WP's template "How long ago", formatted for readability, but with extant bugs)
 
m (original template name has changed to something that's actually logical)
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{AgeFull/exp
<includeonly>{{#if:{{{year|}}}
|
|{{#if:{{{month|}}}
{{#ifexpr:
   |{{#if:{{{day|}}}
   (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) -
  |{{AgeFull/display
     (((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0) * 100
     |years={{#expr:{{CURRENTYEAR}}-{{{year}}}-{{#ifexpr:{{CURRENTMONTH}}>{{{month}}}
  > {{{2|{{{month|12}}}}}}
    |0
  |
    |{{#ifexpr:{{CURRENTMONTH}}<{{{month}}}
  {{#expr:{{#expr:((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0}} -
      |1
    {{{1|{{{year|2005}}}}}}}}
      |{{#ifexpr:{{CURRENTDAY}}>={{{day}}}
  |
      |0
  {{#ifexpr:
      |1
    (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) -
      }}
      (((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0) * 100
      }}
    < {{{2|{{{month|12}}}}}}
    }}}}
    |
    |months={{#expr:{{CURRENTMONTH}}-{{{month}}}+{{#ifexpr:{{CURRENTDAY}}>={{{day}}}
    {{#expr:{{#expr:((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0}} -
    |{{#ifexpr:{{CURRENTMONTH}}>={{{month}}}
      {{{1|{{{year|2005}}}}}} - 1 }}
      |0
     |
      |12
    {{#ifexpr:
      }}
      (((({{#time:YmdHis}} / 1000000) round 0))) -
    |{{#ifexpr:{{CURRENTMONTH}}>{{{month}}}
        (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) * 100
      |-1
      >= {{{day|31}}}
      |11
      |
      }}
      {{#expr:{{#expr:((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0}} -
    }}}}
        {{{1|{{{year|2005}}}}}}}}
     |days={{#ifexpr:{{CURRENTDAY}}>={{{day}}}
       |
    |{{#expr:{{CURRENTDAY}}-{{{day}}}
       {{#expr:{{#expr:((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0}} -
      }}
        {{{1|{{{year|2005}}}}}} - 1}}
    |{{#expr:{{Gsd
      |year={{CURRENTYEAR}}
      |month={{CURRENTMONTH}}
      |day={{CURRENTDAY}}}}-{{Gsd
       |year={{CURRENTYEAR}}
       |month={{#expr:{{CURRENTMONTH}}-1}}
      |day={{{day}}}
      }}}}
    }}
     }}
     }}
  }}
  |{{#ifexpr:{{CURRENTMONTH}}={{{month}}}
}}
    |{{#ifexpr:{{CURRENTYEAR}}={{{year}}}
|
    |0&nbsp;years
{{#ifexpr:
    |{{#expr:{{CURRENTYEAR}}-{{{year}}}-1}}&nbsp;or {{AgeFull/display
  (((({{#time:YmdHis}} / 1000000) round 0))) -
       |years={{#expr:{{CURRENTYEAR}}-{{{year}}}}}
    (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) * 100
       }}
  >= {{{3|{{{day|31}}}}}}
    }}
  |
     |{{#ifexpr:{{CURRENTMONTH}}>{{{month}}}
  {{#ifexpr:
    |{{#ifexpr:{{CURRENTYEAR}}={{{year}}}
    (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) -
      |<!--null value-->
      (((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0) * 100 -
       |{{AgeFull/display
      {{{2|{{{month|31}}}}}}
      |years={{#expr:{{CURRENTYEAR}}-{{{year}}}}}
    >= 0
      }} and
    |
       }} {{#expr:{{CURRENTMONTH}}-{{{month}}}-1}}&nbsp;or {{AgeFull/display
    {{#expr:(((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) -
       |months={{#expr:{{CURRENTMONTH}}-{{{month}}}}}
      (((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0) * 100 -
      {{{2|{{{month|12}}}}}}}}
    |
    {{#expr:(((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) -
      (((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0) * 100 -
       {{{2|{{{month|12}}}}}} + 12}}
  }}
  |
  {{#ifexpr:
    (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) -
      (((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0) * 100 -
      {{{2|{{{month|31}}}}}}
    > 0
    |
    {{#expr:(((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) -
       (((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0) * 100 -
      {{{2|{{{month|12}}}}}} - 1}}
     |
    {{#expr:(((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) -
      (((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0) * 100 -
      {{{2|{{{month|12}}}}}} + 11}}
  }}
}}
|
{{#ifexpr:
  (((({{#time: YmdHis}} / 1000000) round 0))) -
    (((({{#time: YmdHis}} / 1000000) round 0)) / 100 round 0) * 100
  >= {{{3|{{{day|31}}}}}}
  |
  {{#expr:{{#expr:(((({{#time:YmdHis}} / 1000000) round 0))) -
    (((({{#time: YmdHis}} / 1000000) round 0)) / 100 round 0) * 100}} -
    {{{3|{{{day|31}}}}}}}}
  |
  {{#ifexpr:
    (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) -
      (((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0) * 100
    = 5
    or
    (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) -
       (((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0) * 100
    = 7
    or
    (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) -
      (((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0) * 100
    = 10
    or
    (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) -
      (((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0) * 100
    = 12
    |
    {{#expr:{{#expr:(((({{#time:YmdHis}} / 1000000) round 0))) -
      (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) * 100}} -
      {{{3|{{{day|31}}}}}} + 30}}
    |
    {{#ifexpr:
      (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) -
        (((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0) * 100
      = 1
      or
       (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) -
        (((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0) * 100
      = 2
      or
      (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) -
        (((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0) * 100
      = 4
      or
      (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) -
        (((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0) * 100
      = 6
      or
      (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) -
        (((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0) * 100
      = 8
      or
      (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) -
        (((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0) * 100
      = 9
      or
      (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) -
        (((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0) * 100
      = 11
       |
      {{#expr:{{#expr:(((({{#time:YmdHis}} / 1000000) round 0))) -
        (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) * 100 }} -
        {{{3|{{{day|31}}}}}} + 31 }}
      |
      {{#ifexpr:
        ((({{#time:YmdHis}} / 1000000) round 0)) / 10000 round 0 mod 4
        = 0
        |
        {{#expr:{{#expr:(((({{#time:YmdHis}} / 1000000) round 0))) -
          (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) * 100}} -
          {{{3|{{{day|31}}}}}} + 29}}
        |
        {{#expr:{{#expr:(((({{#time:YmdHis}} / 1000000) round 0))) -
          (((({{#time:YmdHis}} / 1000000) round 0)) / 100 round 0) * 100 }} -
          {{{3|{{{day|31}}}}}} + 28}}
       }}
       }}
    |{{#ifexpr:{{CURRENTYEAR}}={{#expr:{{{year}}}+1}}
      |<!--null value-->
      |{{AgeFull/display
      |years={{#expr:{{CURRENTYEAR}}-{{{year}}}-1}}
      }} and
      }} {{#expr:{{CURRENTMONTH}}-{{{month}}}+11}}&nbsp;or {{#expr:{{CURRENTMONTH}}-{{{month}}}+12}}&nbsp;months
    }}
    }}
  }}
  |{{#ifexpr:{{CURRENTYEAR}}={{{year}}}
  |0&nbsp;years
  |{{#expr:{{CURRENTYEAR}}-{{{year}}}-1}}&nbsp;or {{AgeFull/display
    |years={{#expr:{{CURRENTYEAR}}-{{{year}}}}}
     }}
     }}
  }}
   }}
   }}
}}
|some time
}}
}}</includeonly><noinclude>Copied from Wikipedia's [[wp:Template:Age in years, months and days|Age in years, months and days]] template. The three parameters are "year", "month", and "day", all optional. Here's what happens if you supply a specific date:
 
"Oni is <nowiki>{{AgeFull|year=2001|month=1|day=29}}</nowiki> old"<br />
yields<br />
Oni is {{AgeFull|year=2001|month=1|day=29}} old
 
whereas "Oni is <nowiki>{{AgeFull|year=2001|month=1}}</nowiki> old"<br />
yields<br />
Oni is {{AgeFull|year=2001|month=1}} old
 
and "Oni is <nowiki>{{AgeFull|year=2001}}</nowiki> old"<br />
yields<br />
Oni is {{AgeFull|year=2001}} old
 
If you're content with just getting an age in whole years and you don't want the equivocating "X or Y years old", use the simpler template [[Template:Age]].
 
[[Category:Utility templates]]</noinclude>

Latest revision as of 02:31, 28 June 2022

Copied from Wikipedia's Age in years, months and days template. The three parameters are "year", "month", and "day", all optional. Here's what happens if you supply a specific date:

"Oni is {{AgeFull|year=2001|month=1|day=29}} old"
yields
Oni is 23 years, 3 months, and 13 days old

whereas "Oni is {{AgeFull|year=2001|month=1}} old"
yields
Oni is 23 years and 3 or 4 months old

and "Oni is {{AgeFull|year=2001}} old"
yields
Oni is 22 or 23 years old

If you're content with just getting an age in whole years and you don't want the equivocating "X or Y years old", use the simpler template Template:Age.