Wikipedia:Lua/Modul/DateTime/en
Wikipedia:Lua Modul DateTime en
| Vorlagenprogrammierung | Diskussionen | Lua | Test | Unterseiten | |||
| Modul | Deutsch | English
|
Modul: | Dokumentation | |||
DateTime – Module containing methods for the interpretation of date and time information, as well as computation, comparison and presentation.
The module is dedicated to tasks beyond parser functions #time and #timel capabilities.
Any unambiguous date formats in local area and English should be recognized as input.
Functions for templates
format
Format a date/time value.
Parameters (all optional; whitespace around will be ignored):
- 1
- Specification of date or time
now– now (Default)- Interpretable format; for examples see test page.
- Leading
#provides number of seconds since 1st of January 1970 (UTC) – unix time. etc. will be treated as regular space.- 2
- Format specification
- as for
#time - according to special declaration
- as for
- lang
- Special language request (code according to ISO 639 etc.)
- Possible values: local project language (here:
dedefault);de-ATand almost all languages with a Wikipedia assigned. On unknown language variant the basic language is native fallback. Letter casing will be ignored.
- Possible values: local project language (here:
- shift
- Moving point in time
- As for
#time(2nd parameter) - Possible values:
1 dayor2 years agoas well as-5 monthsetc. - Specifications
tomorroworyesterdayas well asnext Fridayare possible only if 1 is related tonow. - Different from
#timea particular reference time is possible. - A single number without unit will be interpreted as number of seconds, may be positive or negative, not necessary integer (decimal period).
- As with
#timeon passing month and year termination by something else than even interval an unexpected result may arrive. Moreover, it is not clear what one month after May 31st is supposed to be.
- As for
- noerror
- Suppress error message
- Possible values: nothing or
0(default);1else - In general a message marked by
class="error"will be presented. - If the result on
noerror=1is an empty value the input has been invalid.
- Possible values: nothing or
Result: Formatted presentation.
- Other than with parser function missing information on input do not cause errors or undesired completions, but the output will be limited to those elements which have been present when called.
lt le eq ne ge gt
These functions compare first and second parameter; as date or time input in any recognized format or now if not provided.
- Result is
1, if condition is met, else “nothing”.
In particular the functions mean:
lt– less thanle– less or equaleq– equalne– not equalge– greater or equalgt– greater
failsafe
Version ID: 2023-10-03
- optional parameter
1– required version, or keywordwikidata
Returns:
- (empty), if minimal version condition not matched
- local version otherwise, or registered on Wikidata (
2023-10-03) whenwikidata
Examples and test page
There are tests available to illustrate this in practice.
Use in another Lua module
All of the above functions can be called from other Lua modules, if not Lua library function anyway. Use require(); the below code checks for errors loading it:
local lucky, DateTime = pcall( require, "Module:DateTime" )
if type( DateTime ) == "table" then
DateTime = DateTime.DateTime()
else
-- In the event of errors, DateTime is an error message.
return "<span class=\"error\">" .. DateTime .. "</span>"
end
Usage
This is a general library; use it anywhere.
- Sort/cellDate – Application for sort keys
Dependencies
- Modul:DateTime/local – language or project specific adaptions
Content Disclaimer
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.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.