Wikipedia:Lua/Modul/DateTime/en

Aus Wikipedia
Vorlagenprogrammierung Diskussionen Lua Unterseiten
Modul Deutsch English

Modul: Dokumentation
Weiterleitung der Diskussionsseite fehlt

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[Am Gwëntext werkeln]

format[Am Gwëntext werkeln]

Format a date/time value.

Parameters (all optional; whitespace around will be ignored):

1
Specification of date or time
nownow (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
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.
shift
Moving point in time
  • As for #time (2nd parameter)
  • Possible values: 1 day or 2 years ago as well as -5 months etc.
  • Specifications tomorrow or yesterday as well as next Friday are possible only if 1 is related to now.
  • 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.
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.

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[Am Gwëntext werkeln]

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 than
  • le – less or equal
  • eq – equal
  • ne – not equal
  • ge – greater or equal
  • gt – greater

failsafe[Am Gwëntext werkeln]

Version ID: 2020-09-30

  • optional parameter 1 – required version, or keyword wikidata

Returns:

  • (empty), if minimal version condition not matched
  • local version otherwise, or registered on Wikidata (2020-09-30) when wikidata

Examples and test page[Am Gwëntext werkeln]

There are tests available to illustrate this in practice.

Use in another Lua module[Am Gwëntext werkeln]

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



This is a general library; use it anywhere.

Dependencies[Am Gwëntext werkeln]