Tostkeoydouxyod (talk) 17:21, 15 May 2022 (UTC)Reply Date active: 2011-always
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
@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)
{{extract|currentdate|add=-1y}} → 12 August 2025{{extract|currentdate|add=-1y|show=year}} → 2025local last_year = require('Module:Date')._current.year - 1
local last_year = os.date('!*t').year - 1
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)
:text() method and I'm not entirely sure how to do that...@Johnuniq: is there a way to detect the input format used to build a date? For example:
local Date = require('Module:Date')._Date
mw.log(Date('1 July 2016')) -- Outputs 1 July 2016
mw.log(Date('July 1, 2016')) -- Outputs 1 July 2016
Now I know that I can override the output with :text('mdy') but say I do not know the format that is being supplied... I want to accept both mdy format as well as dmy format. I want to do some calculation, then return the result in the same format it was supplied. So if I started with mdy, I want to end with mdy and ditto for dmy.
Is there someway to detect which format was sent in?? If not, is this something that could be added? FWIW this is blocking a merge that I can explain further if you are interested, but suffice it to say this capability would be VERY helpful. Zackmann (Talk to me/What I been doing) 03:38, 4 December 2025 (UTC)
d is a valid date (that is, not nil), d.format is a string: dmy, mdy, ymd, error. See {{extract}} which documents show=format. I had forgotten how a module does that so I looked in Module:Date/example (linked in the doc) and it has an example. Johnuniq (talk) 04:45, 4 December 2025 (UTC)
@Krinkle: I don't have spare thinking capacity at the moment and cannot follow the reason (phab:T416616) for the recent change at Module:Date. I'm not complaining, I'm just saying I would need some quality time to understand the point. Unfortunately the module exports _current described as "Table with the current year, month, day, hour, minute, second." in documentation on the module page. However, the change means "minute, second" is now "min, sec". I don't know of any modules using those fields but it's a big world and there may be a problem. I'll try to think about this in the coming days but a metatable like there was before might be needed? I put a demo at Module:Sandbox/Johnuniq/temp. Johnuniq (talk) 09:11, 18 February 2026 (UTC)
os.date() in the debug console, and other modules can likewise use their own call. Krinkle (talk) 09:35, 18 February 2026 (UTC)
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.