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
Bearbeitenformat
BearbeitenFormat 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:
de
default);de-AT
and 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 day
or2 years ago
as well as-5 months
etc. - Specifications
tomorrow
oryesterday
as well asnext Friday
are possible only if 1 is related tonow
. - Different from
#time
a 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
#time
on 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);1
else - In general a message marked by
class="error"
will be presented. - If the result on
noerror=1
is 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
BearbeitenThese 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
BearbeitenVersion 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
BearbeitenThere are tests available to illustrate this in practice.
Use in another Lua module
BearbeitenAll 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
BearbeitenThis is a general library; use it anywhere.
- Sort/cellDate – Application for sort keys
Dependencies
Bearbeiten- Modul:DateTime/local – language or project specific adaptions