Module talk:Date
Template-protected edit request on 15 May 2022
[edit]![]() | This edit request has been answered. Set the |answered= parameter to no to reactivate your request. |
Tostkeoydouxyod (talk) 17:21, 15 May 2022 (UTC)
Date active: 2011-always
Not done not a scrubinto change. — xaosflux Talk 17:25, 15 May 2022 (UTC)
Date math
[edit]@Johnuniq: (or anyone else) is there an easy way to basic date math? I.e.
local today = Date('currentdate')
local last_year = today - 1.year
I know I can grab the year, subtract one and form a new date by mashing strings together but before I go that route I want to make sure I’m not missing an easier solution… Thanks! Zackmann (Talk to me/What I been doing) 20:32, 30 September 2025 (UTC)
- @Zackmann08: It looks like you want to do this in a module. Before looking at that, you might like to know about {{extract}}. Examples:
{{extract|currentdate|add=-1y}}
→ 3 October 2024{{extract|currentdate|add=-1y|show=year}}
→ 2024
- Of course #time can do easily do the above. For a module, if all that is wanted is last year, try
local last_year = require('Module:Date')._current.year - 1
- Johnuniq (talk) 23:46, 30 September 2025 (UTC)
- Actually, Module:Date is not needed.
local last_year = os.date('!*t').year - 1
- Johnuniq (talk) 23:51, 30 September 2025 (UTC)
- Stellar! Thanks so much for the info! - Zackmann (Talk to me/What I been doing) 00:46, 1 October 2025 (UTC)
- Actually, Module:Date is not needed.
Month abbreviations
[edit]In my work on Module:Person date I ran into an issue where abbreviated months (i.e. Aug. Jan. etc.) were not working. I traced through my code and turns out it comes down to a call where I basically do Date('1 Apr. 2016')
. By my read of lines 571-582, those abbreviations are not supported by Module:Date. I'm wondering if they can be? I've found a number of cases in articles of people posting dates with this abbreviated form. I think this is a simple change which I have mocked up in the sandbox (see the comparison). That being said, given how widely used this module is I am VERY wary of implementing any change without a thorough code review. @Johnuniq: would love to hear your thoughts. --Zackmann (Talk to me/What I been doing) 08:12, 3 October 2025 (UTC)
- The ustring family is very clever but it is not needed in this case. I put a more efficient version in the sandbox. It's probably ok (I ran some tests). The issue is what abbreviations should be supported as opposed to fixing the wikitext. What about '1 Ap. 2016' and similar? Johnuniq (talk) 08:50, 3 October 2025 (UTC)
- That looks perfect to me. I would think that the non-period abbreviations you already have spelled out in lines 571-582 cover it. A google search turned up this from the Yale Library for what that's worth. I don't think I've ever seen anyone intentionally abbreviate a month with only 2 letters (Oc or De for example) and I'm not in favor of trying to cover EVERY scenario, but covering the basic case of a period after a 3 (or in the case of Sept, a 4) letter month seems like it would be super helpful. --Zackmann (Talk to me/What I been doing) 09:08, 3 October 2025 (UTC)