Module talk:Date time
Should nil values be confined to the least significant values?
Should the module be modified to require that there be no nil values between the most significant value and the least significant values. For example, if month is nil but day is 1, should that trigger an error?
Since a time zone is sometimes handled by some of the templates that call this, it might be useful to either validate the time zone, or at least return the number of the least significant non-nil value. For example, if all the values are non-nil for minute and above, it makes sense to have a non-nil time zone, and returning 5 would provide that information to the calling function. If the least significant non-nil value were day, it's questionable whether it's valid to use a time zone. Jc3s5h (talk) 23:18, 26 February 2025 (UTC)
- Since this module is meant for a date validation, I don't think a date with a day and year and without a month can pass any validation. So I would say that it should trigger an error. Your question has also lead me to notice that currently such a call triggers an unexpected error in the code.
- Regarding time zones. I haven't touched that, but if you can either write the code or have a complete detailed plan on what passes and what fails, I can see to adding it. Gonnym (talk) 10:32, 27 February 2025 (UTC)
- I have exactly one Lua module under my belt, and I own a book about Lua, so I should have no problem writing the code. (What's the emoji for sarcasm?} I have a few questions before I dig into it.
- Currently Start date correctly renders a least significant parameter (LSP) of month, or minute, but not hour. ISO 8601 can express a time with a precision of hours and a time zone correctly (example 2025-02-27T6Z). So should we require a LSP of minute or second to allow a time zone, or should we also allow hour?
- Another thought is whether the production of the character string for the ISO 8601 should be brought into this module, so we don't have different implementations in Start date, End date, Birth date, Death date, and wherever else the module is invoked. (I don't know how to list what pages invoke a module.) Jc3s5h (talk) 11:59, 27 February 2025 (UTC)
- In terms of dates, speak to me like a complete idiot as I don't understand what LSP is. Since I don't understand it, I also don't understand what is missing or needs to be checked. If you tell me "it needs to error when x happens", I can work with that.
- I've added tests to Module talk:Date time validation/testcases so you can see what passes and what fails. You can add new tests to Module:Date time validation/testcases if you feel some are missing.
- Regarding the production of the string, that is currently outside the scope of this module, as it only validates the data, not creates it. If needed, we can create a different module for the creation of the data (it's better to have defined scope for code). Gonnym (talk) 12:09, 27 February 2025 (UTC)
Here are a few test cases
{{Start date| 2021 |4|27||||Z|df=y}}
Questionable rendered date: Error: A timezone cannot be set without a day and hour (help)
Incorrect ISO 8601: 2021-04-27Z
{{Start date| 2022 |4|27|8|||Z|df=y}}
Incorrect rendered date: 08:00, 27 April 2022 (UTC)
Correct ISO 8601: 2022-04-27T08Z
{{Start date| 2023 |4|27|8|12||Z|df=y}}
Correct rendered date: 08:12, 27 April 2023 (UTC)
Correct ISO 8601: 2023-04-27T08:12Z
All the ISO 8601 values were copied from the html of the rendered page User:Jc3s5h/sandbox4.