I have been adding error-checking code to age-related templates (see ‹The template Category link is being considered for merging.› 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|07}} | July 1969 (age 54–55) |
{{Death year and age|2023|1973}} | 2023 (aged 49–50) |
{{Death year and age|2023|1973|07}} | July 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)
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)
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–20Are there any objections to moving this sandbox code to the template? – Jonesey95 ( talk) 03:55, 2 June 2015 (UTC)
{{Death date and age|1911|12|15|1911}}
→ December 15, 1911 (aged 0){{Death date and age/sandbox|1911|12|15|1911}}
→ Error: Need valid death date (first date): year, month, day{{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: Need valid death date (first date): year, month, dayI have been adding error-checking code to age-related templates (see ‹The template Category link is being considered for merging.› 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|07}} | July 1969 (age 54–55) |
{{Death year and age|2023|1973}} | 2023 (aged 49–50) |
{{Death year and age|2023|1973|07}} | July 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)
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)
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–20Are there any objections to moving this sandbox code to the template? – Jonesey95 ( talk) 03:55, 2 June 2015 (UTC)
{{Death date and age|1911|12|15|1911}}
→ December 15, 1911 (aged 0){{Death date and age/sandbox|1911|12|15|1911}}
→ Error: Need valid death date (first date): year, month, day{{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: Need valid death date (first date): year, month, day