Difference between revisions of "Template:Date precision/doc"
imported>RexxS (Creating Template:Date precision documentation) |
imported>Pppery |
||
| Line 1: | Line 1: | ||
{{Documentation subpage}} | {{Documentation subpage}} | ||
| + | {{lua|Module:WikidataIB}} | ||
<!-- Add categories where indicated at the bottom of this page and interwikis at Wikidata (see [[Wikipedia:Wikidata]]) --> | <!-- Add categories where indicated at the bottom of this page and interwikis at Wikidata (see [[Wikipedia:Wikidata]]) --> | ||
This template develops the <code>getDatePrecision()</code> function from [[Module:WikidataIB]] for use in comparisons. | This template develops the <code>getDatePrecision()</code> function from [[Module:WikidataIB]] for use in comparisons. | ||
Revision as of 21:31, 10 July 2020
| 40px | This is a documentation subpage for Template:Date precision. It contains usage information, categories and other content that is not part of the original template page. |
| This template uses Lua: |
This template develops the getDatePrecision() function from Module:WikidataIB for use in comparisons.
The getDatePrecision() function takes a property-ID (as the first unnamed parameter) and an entity-ID (as |qid=) and returns the precision of the first best date value for the given property of the given entity. If the entity-ID is not given, the entity-ID connected to the current page is used.
The precisions are an integer from 0 to 11, where the values are defined at mw:Wikibase/DataModel#Dates_and_times:
- 0 - billion years, 1 - hundred million years, ..., 6 - millenia, 7 - century, 8 - decade, 9 - year, 10 - month, 11 - day
The getDatePrecision() function returns an empty string when there is no precision, or the property is not a date, or the current page is not connected. This can cause problems in templates if an attempt is made to compare the returned value with a number, so this template traps that and returns either the second unnamed parameter or 0 if that is not supplied.
Examples
- Lua error in Module:Wd at line 196: attempt to index field 'wikibase' (a nil value). (Q52063097):
{{Date precision|P569|qid=Q52063097}}→ Script error: No such module "If empty". - Lua error in Module:Wd at line 196: attempt to index field 'wikibase' (a nil value). (Q42)
{{Date precision|P569|qid=Q42}}→ Script error: No such module "If empty". - No qid:
{{Date precision|P569|qid={{{qid|}}} }}→ Script error: No such module "If empty". - No qid, default set to 99:
{{Date precision|P569|qid={{{qid|}}}|99}}→ Script error: No such module "If empty".
Testing for precision can be done like this, and the default output can be changed by assigning the default a large number:
- Lua error in Module:Wd at line 196: attempt to index field 'wikibase' (a nil value). (Q52063097):
{{#ifexpr:{{Date precision|P569|qid=Q52063097}} > 8 |This if it's year or smaller|This if it's more than a year}}→ Expression error: Unexpected < operator. - Lua error in Module:Wd at line 196: attempt to index field 'wikibase' (a nil value). (Q42):
{{#ifexpr:{{Date precision|P569|qid=Q42}} > 8 |This if it's year or smaller|This if it's more than a year}}→ Expression error: Unexpected < operator. - No qid:
{{#ifexpr:{{Date precision|P569|qid={{{qid|}}} }} > 8 |This if it's year or smaller|This if it's more than a year}}→ Expression error: Unexpected < operator. - No qid, default set to 99:
{{#ifexpr:{{Date precision|P569|qid={{{qid|}}}|99}} > 8 |This if it's year or smaller|This if it's more than a year}}→ Expression error: Unexpected < operator.