Template talk:Age in years
Discussion of proposed change to make this template more accurate
[edit]I have been adding error-checking code to age-related templates (see Category:Pages using age template with invalid date) recently. As part of that work, I have found a few templates that do not do math correctly, so I have been fixing them. I fixed this "Age in years" template to correct the way it displays ages. That change has been reverted.
At present, since my change has been reverted, the template says that someone born in 2000 is currently 15 years old (in 2015), but that is obviously not correct. Someone born in 2000 is currently either 15 years old (if they have already had a birthday this year) or 14 years old (if they have not yet had a birthday this year).
The code in the sandbox corrects this math problem. Here's the existing template, as it has existed (with incorrect math) for a while:
{{Age in years|2000}}
yields 23–24.
{{Age in years|1900|1950}}
yields 49–50.
Here's the code in the sandbox:
{{Age in years/sandbox|2000}}
yields 23–24.
{{Age in years/sandbox|1900|1950}}
yields 49–50.
The display of this age shows in the same manner as {{birth year and age}} and {{death year and age}}, as in the following examples:
Template text | Result |
---|---|
{{Birth year and age|1969}} | 1969 (age 54–55) |
{{Birth year and age|1969|11}} | November 1969 (age 54–55) |
{{Death year and age|2023|1973}} | 2023 (aged 49–50) |
{{Death year and age|2023|1973|11}} | November 2023 (aged 49–50) |
This template is primarily used in articles about people. This template is used by {{Death date and age}}, which is now displaying ages at death inaccurately in articles such as George Wythe.
I would like to reapply this simple and logical math fix to this template so that it is accurate and in line with other age calculation templates where the exact start date is uncertain. – Jonesey95 (talk) 02:00, 19 April 2015 (UTC)
- Agree - Seems a reasonable change to correct the wrong display. MilborneOne (talk) 07:03, 19 April 2015 (UTC)
- The documentation does say "This template should not be used for ages of humans or animals.". I wonder if there are inanimate articles where a date range is undesirable, and maybe we should create a new template for use with humans and animals? Periglio (talk) 12:41, 19 April 2015 (UTC)
- I wrote that documentation yesterday, since the template is not accurate for the reasons explained above. If the sandbox code is changed, I would remove that bit of documentation. {{Age}} specifically returns full years only (and has since its creation in 2007); that template should be used for inanimate objects.
- As I have said on other Talk pages, the age/birth/death templates need an overhaul, but in the meantime, this template, which is used in 600+ articles, the vast majority of which are about humans, should show accurate ages. – Jonesey95 (talk) 14:03, 19 April 2015 (UTC)
- Good answer. Quickly scanning through the where used list, I found none where the use was non-biographical. Therefore, I agree with the change in order to keep the age accurate and consistent with the rest of the Wikipedia templates.
- The documentation does say "This template should not be used for ages of humans or animals.". I wonder if there are inanimate articles where a date range is undesirable, and maybe we should create a new template for use with humans and animals? Periglio (talk) 12:41, 19 April 2015 (UTC)
Negative years
[edit]In List of Justices of the Supreme Court of the United States, the Age in Years template is used to get the length of time a person was on the US Supreme Court. One Justice served less than a year, and the code "{{Age in years|1795|1795}}" shows up as "-1–0". Should the template check for the special case of start year = end year, and say something like "< 1 year"? --ΨΦorg (talk) 19:34, 1 June 2015 (UTC)
- That table looks awkward with those year ranges. I would use {{Age}} instead, which gives you a whole number of years. That said, I'll see if I can add a statement to this template to test for the two parameters being equal and output a zero. – Jonesey95 (talk) 02:03, 2 June 2015 (UTC)
I added code to check for zero ages, as well as code to display an error message for negative ages.
Examples using new code in the sandbox:
{{Age in years/sandbox|2015}}
→ 8–9{{Age in years/sandbox|1911|1911}}
→ 0{{Age in years/sandbox|1910|1911}}
→ 0–1{{Age in years/sandbox|2010|1911}}
→ Error: The second date must be later in time than the first date{{Age in years/sandbox|1910|1930}}
→ 19–20
Are there any objections to moving this sandbox code to the template? – Jonesey95 (talk) 03:55, 2 June 2015 (UTC)
- And testing/fixing a template that transcludes this one:
{{Death date and age|1911|12|15|1911}}
→ December 15, 1911 (aged 0){{Death date and age/sandbox|1911|12|15|1911}}
→ December 15, 1911 (aged 0){{Death date and age|2010|12|15|2015}}
→ Error: Death date (first date) must be later in time than the birth date (second date){{Death date and age/sandbox|2010|12|15|2015}}
→ Error: Death date (first date) must be later in time than the birth date (second date)
- That looks like an improvement. There is a redundant error message, but I'm not interested in coding for that. – Jonesey95 (talk) 04:14, 2 June 2015 (UTC)
- Good work, I say go for it! Periglio (talk) 04:26, 2 June 2015 (UTC)
- Done. – Jonesey95 (talk) 05:02, 2 June 2015 (UTC)