Module talk:Age
| This is the talk page for discussing improvements to the Age module. |
|
| Archives: 1Auto-archiving period: 6 months |
| Module:Age is permanently protected from editing as it is a heavily used or highly visible module. Substantial changes should first be proposed and discussed here on this page. If the proposal is uncontroversial or has been discussed and is supported by consensus, editors may use {{edit template-protected}} to notify an administrator or template editor to make the requested edit.
|
Test cases
[edit]So regardless of if any changes are made to Module:Age per the current discussion, I do think it would be beneficial to have some Module:UnitTests for the module. I found that with a tiny change to the module I can call the functions directly which will allow the unit tests to function. Can you review it and merge it if it looks good? Here is the comparison. I followed the format I have seen in many other Modules. Zackmann (Talk to me/What I been doing) 07:35, 9 October 2025 (UTC)
- Now this is a discussion that should be on the module talk page! Please don't reply here but I'm slow and methodical and would need quite a bit of time to ponder the fact that the frame args are referred to in several different places. Johnuniq (talk) 08:43, 9 October 2025 (UTC)
- @Johnuniq:
Facepalm . Moved the discussion. Let me know if you have any questions! --Zackmann (Talk to me/What I been doing) 09:16, 9 October 2025 (UTC)
- I'm occupied elsewhere at the moment. Have you thought about my "ponder" point above? I haven't thought about whether that needs thought. Johnuniq (talk) 09:19, 9 October 2025 (UTC)
- I will ponder whilst you figure out if pondering is needed... Obviously no rush on this. Get to it when you can. If/when it is merged, I will start making testcases.
Zackmann (Talk to me/What I been doing) 09:21, 9 October 2025 (UTC)
- @Zackmann08: See my edit at Module:Age/testcases. Why not call the templates? Johnuniq (talk) 08:15, 11 October 2025 (UTC)
- Because...... Looking for witty retort... Error 404. Honestly because I didn't think of that or realize that was doable. I see no reason that shouldn't work just fine.
I'll do that. Zackmann (Talk to me/What I been doing) 08:18, 11 October 2025 (UTC)
- Because...... Looking for witty retort... Error 404. Honestly because I didn't think of that or realize that was doable. I see no reason that shouldn't work just fine.
- @Zackmann08: See my edit at Module:Age/testcases. Why not call the templates? Johnuniq (talk) 08:15, 11 October 2025 (UTC)
- I will ponder whilst you figure out if pondering is needed... Obviously no rush on this. Get to it when you can. If/when it is merged, I will start making testcases.
- I'm occupied elsewhere at the moment. Have you thought about my "ponder" point above? I haven't thought about whether that needs thought. Johnuniq (talk) 09:19, 9 October 2025 (UTC)
- @Johnuniq:
Updating df/mf syntax
[edit]Per this tfd I have refactored the module's code for {{dda}} and {{bda}} so that they will respect the format of the input date. To be clear:
- The change is that if you supply a date in df format, the result will ALSO be in df format (without you needing to specify
|df=yes)- In other words, with my change:
{{bda|2 May 1990}}→ 2 May 1990 - Prior to my change the date would be converted to mf by default:
{{bda|2 May 1990}}→ May 2, 1990
- In other words, with my change:
|mf=&|df=still work as before and will override the default behavior
The code diff can be see here.
Zackmann (Talk to me/What I been doing) 06:30, 5 December 2025 (UTC)
- As in above sections, these templates are used in many places and it's hard to know what the effect of a change like this would be. I suppose that if no df or mf parameters are used, it's reasonable to assume that someone expected the output format to follow the input. I'll think about it over the next couple of days and will have a look at on old article dump download to see if any problems emerge. Please remind me if I haven't posted by next Tuesday. Johnuniq (talk) 06:56, 5 December 2025 (UTC)
- @Johnuniq: to be clear, didn't mean to overrule you or anything. Kind forgot about the above discussion. I certainly want you to give this a good look over. A few thoughts:
- Primary concern is that nothing truly break. I.E. Someone inputs 1 date and gets a completely different date or an error. That is priority number 1.
- As you hinted at above, I cannot fathom a case where someone would supply a day-first date and then be disappointed that they got a day-first date back. (Note that
|mf=&|df=still work as previous) - Assuming I haven't missed anything, the way I see it, the WORST case scenario is that someone is confused why all of a sudden the date that was displaying (for example) December 4, 2025 is now saying 4 December 2025...
- In that case, I would assume the first they would do is look at the code and see "oh, the code is written df, so that is probably why it is displaying df...
- Note that this change ONLY affects the {{dda}} & {{bda}} functions.
- Think that is it for now. If you have questions, comments or concerns absolutely let me know! Cheers. Zackmann (Talk to me/What I been doing) 07:03, 5 December 2025 (UTC)
- I'm not disagreeing. An unfortunately large slice of experience means that I have seen many cases where thorough investigation revealed issues that were not apparent at first. Johnuniq (talk) 07:13, 5 December 2025 (UTC)
- Sounds great. appreciate your insight. Zackmann (Talk to me/What I been doing) 07:21, 5 December 2025 (UTC)
- I'm not disagreeing. An unfortunately large slice of experience means that I have seen many cases where thorough investigation revealed issues that were not apparent at first. Johnuniq (talk) 07:13, 5 December 2025 (UTC)
- @Johnuniq: to be clear, didn't mean to overrule you or anything. Kind forgot about the above discussion. I certainly want you to give this a good look over. A few thoughts:
I have started looking at the changes. They are good but I haven't done my full check of results yet. Meanwhile, here are some differences to think about.
{{Birth date and age|2001|4|1}}→ April 1, 2001{{Birth date and age/sandbox|2001|4|1}}→ April 1, 2001{{Birth date and age|year=2001|month=4|day=1}}→ April 1, 2001{{Birth date and age/sandbox|year=2001|month=4|day=1}}→ April 1, 2001{{Death date and age|2005|4|12|2000|4|13}}→ April 12, 2005 (aged 4){{Death date and age/sandbox|2005|4|12|2000|4|13}}→ April 12, 2005 (aged 4)
More in a day or two. Johnuniq (talk) 06:03, 6 December 2025 (UTC)
- So I literally JUST came across that a few minutes ago when reviewing the testcases. That was not an intended change. Without any investigation, my guess is that Module:Date defaults to 'df' when constructing a date in that format... Not certain and will investigate further. I will fix that as those should not be changing. - Zackmann (Talk to me/What I been doing) 06:19, 6 December 2025 (UTC)
- It will just be some logic twist in Module:Age due to the input date format being ymd. I will look later. Johnuniq (talk) 06:21, 6 December 2025 (UTC)
- If you get to it before me, awesome! But I'm happy to unpack it tomorrow. Too late on a Friday night my time to start down this rabbit hole.
- Zackmann (Talk to me/What I been doing) 06:23, 6 December 2025 (UTC)
- @Johnuniq: so I'm stuck. The issue seems to lie in the if loop starting at Line 660. When you construct a date with
Date(...,y,m,d)thend.formatwill be 'dmy'. Since.formatis read-only, there is no 'setter' to override that. Not sure what the best solution is... I guess we could change the formatting so that instead of constructing the date in 'ymd' it constructs it in 'mdy', but that seems like a sizable refactor. Maybe the easier solution is to refactor Module:Date to allow you to set the value for the format associate with a specific instance of a date? Off hand that seems like it would require less code changes and therefore be less risky overall? Open to your thoughts and suggestions. Zackmann (Talk to me/What I been doing) 19:14, 6 December 2025 (UTC)- So Johnuniq I think I found the easiest (and more importantly safest) fix. With this one change, you can pass in a
'mdy'as part of the date constructor to set the default date format. This way, no uses of Module:Date should change, and with this little change, there should be no changes to the bda/dda calls that are using the format{{bda|yyyy|mm|dd}}. You will note that your examples above now produce the same results. Zackmann (Talk to me/What I been doing) 22:53, 6 December 2025 (UTC)
- So Johnuniq I think I found the easiest (and more importantly safest) fix. With this one change, you can pass in a
- @Johnuniq: so I'm stuck. The issue seems to lie in the if loop starting at Line 660. When you construct a date with
- If you get to it before me, awesome! But I'm happy to unpack it tomorrow. Too late on a Friday night my time to start down this rabbit hole.
- It will just be some logic twist in Module:Age due to the input date format being ymd. I will look later. Johnuniq (talk) 06:21, 6 December 2025 (UTC)
@Zackmann08: I have reworked the module for a simpler change. It would be better if Module:Date is only changed if needed, and I don't think it is. Also, I suspect the changes to Module:Age would change the birth/death date format defaults for a couple of other language Wikipedias where df is the default, if they ever updated their code from here. The minor issue mentioned in my 6 December 2025 comments above concerns examples like {{Birth date and age|2001|4|1}} where Module:Date reports that the date format is dmy. It does that because date:text() would give dmy with that input. With that example, there is no specified date format and my change to Module:Age takes that into account. Please have a look and see what you think about the current sandbox code. I'm going to need another couple of days to get back to this for a final check but I think this should work. The following shows the current modules.
- Module:Age • Module:Age/sandbox • same content
- Module:Date • Module:Date/sandbox • same content
Johnuniq (talk) 04:12, 9 December 2025 (UTC)
- @Johnuniq: so that looks perfect to me! I agree that changing only 1 module is FAR better than changing both. That was just the best solution I could come up with. I like yours better. If I can do anything more to further the process, let me know. Otherwise, I await your final stamp of approval when you can give it. Thanks again for the teamwork on this.
Zackmann (Talk to me/What I been doing) 05:49, 9 December 2025 (UTC)
- Done. Johnuniq (talk) 08:08, 10 December 2025 (UTC)
- THANK YOU!! Zackmann (Talk to me/What I been doing) 08:10, 10 December 2025 (UTC)
- Done. Johnuniq (talk) 08:08, 10 December 2025 (UTC)
Fixing birth age templates
[edit]@Johnuniq: on the heels of the successful merge of {{death-date and age}} that we achieved above, I'm looking at doing the same thing with the birth age templates. Behold the clusterf&$k that is the birth age templates...
{{bda|12 December 2020}}→ 12 December 2020{{bda|December 2020}}→ Error: Need valid birth date: year, month, day (should display age as 4-5){{bda|2020|12}}→ Error: Need valid birth date: year, month, day (should display age as 4-5){{b-da|12 December 2020}}→ 12 December 2020 (age 5){{b-da|December 2020}}→ December 2020 (age 5) (should display age as 4-5){{b-da|2020}}→ 2020 (age 6) (should display age as 4-5)
NOTE the "should display" comments above are as of Dec 15, 2025. Those will obviously change in the future...
Before I start down this rabbit hole, I wanted to gauge your willingness to help as you did previously, and ensure that this seems like a worthwhile effort. Any thoughts on the matter? Obviously there is no rush on it... Zackmann (Talk to me/What I been doing) 18:52, 15 December 2025 (UTC)
- Yes, but not now. I have got other stuff to do. Remind me if I'm not back in a week. Johnuniq (talk) 01:00, 16 December 2025 (UTC)
- Sounds good! Happy to reconvene in the new year. ZERO rush on this. Zackmann (Talk to me/What I been doing) 01:02, 16 December 2025 (UTC)
Bug?
[edit]@Gonnym, Ahecht, and Johnuniq: I have now come across 4 separate pages with errors related to Template:Age in years, months, weeks and days (See: Category:Pages using age template with invalid date). NONE of them have had any recent changes and I don't see any recent changes to the template either... I'm totally lost as I cannot find any recent changes that may have caused this to start breaking. Any help greatly appreciated! Zackmann (Talk to me/What I been doing) 22:50, 31 January 2026 (UTC)
- A weird server glitch maybe. It's all good now. When I looked, there were three articles in the category (1, 2, 3). Nothing recent that I could see and an edit/publish on each page cleared the category. Johnuniq (talk) 01:08, 1 February 2026 (UTC)
- Well I'm effing confused. But glad it is all fixed! Sorry for the pings. Zackmann (Talk to me/What I been doing) 05:15, 1 February 2026 (UTC)
- I have sometimes seen this kind of thing before (rarely). Nothing, including Wikidata, appears to have been changed but an error was flagged with the hidden category added. However, it then goes away with nothing being done to fix it. Johnuniq (talk) 07:52, 1 February 2026 (UTC)
- Well I'm effing confused. But glad it is all fixed! Sorry for the pings. Zackmann (Talk to me/What I been doing) 05:15, 1 February 2026 (UTC)
Number formatting via common methods
[edit]Numbers should perhaps be formatted via module:formatnum or mw.lang.formatnum(). This would reduce effort in localizing the module for other wikis. Ipr1 (talk) 15:20, 19 February 2026 (UTC)
- In other modules, I have spent a lot of time providing localization methods but gave up with Module:Date and Age. That's because of all the input date parsing and output month names, and other calendar assumptions that I know nothing about. Johnuniq (talk) 04:13, 20 February 2026 (UTC)