Difference between revisions of "Template:SetDatePropertyValueFromDateString"
Jump to navigation
Jump to search
(Created page with "<noinclude> This template takes a date string in <code><nowiki>yyyy/mm/dd</nowiki></code> format and stores it as a complex date property value using Template:SetDatePropert...") |
|||
(12 intermediate revisions by the same user not shown) | |||
Line 13: | Line 13: | ||
* <code><nowiki>|property=</nowiki></code> - the name of the property. | * <code><nowiki>|property=</nowiki></code> - the name of the property. | ||
* <code><nowiki>|datestring=</nowiki></code> - the date value in yyyy/mm/dd format. The month and day are optional. '''YYYY BC and YYYY BCE formats are allowed for BC years.''' | * <code><nowiki>|datestring=</nowiki></code> - the date value in yyyy/mm/dd format. The month and day are optional. '''YYYY BC and YYYY BCE formats are allowed for BC years.''' | ||
+ | * <code><nowiki>|reporterror=</nowiki></code> - if given, an error message will be printed if no date is found in datestring. | ||
− | </noinclude> | + | </noinclude><includeonly><!-- |
− | <includeonly><!-- | ||
-->{{#if: {{{property|}}}<!-- | -->{{#if: {{{property|}}}<!-- | ||
--><!-- set individual values and build the overall date string | --><!-- set individual values and build the overall date string | ||
-->|{{#if: {{{datestring|}}}<!-- | -->|{{#if: {{{datestring|}}}<!-- | ||
− | --><!-- | + | --><!-- nullify all the variables since they might be defined by the previous call of this function |
− | --><!-- | + | -->{{#vardefine: varYear|}}<!-- |
− | -->|{{#vardefine: varSlash1|{{#pos:{{{datestring|}}}| | + | -->{{#vardefine: varMonth|}}<!-- |
− | -->{{# | + | -->{{#vardefine: varDay|}}<!-- |
− | -->|{{#vardefine: varYear|{{#sub:{{{datestring|}}}|0|{{#expr: {{#var: varSlash1}} | + | --><!-- |
− | -->{{#vardefine: varSlash2|{{#pos:{{{datestring|}}}| | + | -->|{{#vardefine: varSlash1|{{#pos:{{{datestring|}}}|/}}|}}<!-- search for the first occurrence of slash |
+ | -->{{#switch: {{#var: varSlash1}}<!-- | ||
+ | -->|0={{#if: {{{reporterror|}}}| The datestring of property {{{property|}}} doesn't contain any date. |}}<!-- slash is the first symbol: don't do anyhting | ||
+ | -->|={{#vardefine: varYear|{{{datestring|}}}|}}<!-- empty: assume that only the year is given | ||
+ | -->|#default={{#vardefine: varYear|{{#sub:{{{datestring|}}}|0|{{#expr: {{#var: varSlash1}}}} }}|}}<!-- extract the year | ||
+ | -->{{#vardefine: varSlash2|{{#pos:{{{datestring|}}}|/|{{#expr: {{#var: varSlash1}}+1}} }}|}}<!-- search for the next occurrence of slash | ||
-->{{#if: {{#var: varSlash2}}<!-- | -->{{#if: {{#var: varSlash2}}<!-- | ||
-->|{{#vardefine: varMonth|{{#sub:{{{datestring|}}}|{{#expr: {{#var: varSlash1}}+1}}|{{#expr: {{#var: varSlash2}}-{{#var: varSlash1}}-1}}}}|}}<!-- extract the month | -->|{{#vardefine: varMonth|{{#sub:{{{datestring|}}}|{{#expr: {{#var: varSlash1}}+1}}|{{#expr: {{#var: varSlash2}}-{{#var: varSlash1}}-1}}}}|}}<!-- extract the month | ||
Line 33: | Line 38: | ||
--><!-- | --><!-- | ||
− | |||
-->}}<!-- | -->}}<!-- | ||
--><!-- | --><!-- | ||
− | --> | + | --><!-- now store the values |
− | --> | + | -->{{SetDatePropertyValue|property={{{property|}}}|year={{#var: varYear}}|month={{#var: varMonth}}|day={{#var: varDay}}|}}<!-- |
− | |||
− | |||
− | |||
--><!-- | --><!-- | ||
-->}}<!-- if datestring | -->}}<!-- if datestring | ||
-->}}<!-- if property | -->}}<!-- if property | ||
--></includeonly> | --></includeonly> |
Latest revision as of 10:32, 24 August 2016
This template takes a date string in yyyy/mm/dd
format and stores it as a complex date property value using Template:SetDatePropertyValue. This whole headache is necessary to support incomplete date values with BC support.
The template will store up to four values:
{{{property|}}}
- the combined date.{{{property|}}} Year
- the year part.{{{property|}}} Month
- the month part.{{{property|}}} Day
- the day part.
NOTE: As any "set" template, it doesn't print anything on the page, but merely sets the appropriate values.
Parameters:
|property=
- the name of the property.|datestring=
- the date value in yyyy/mm/dd format. The month and day are optional. YYYY BC and YYYY BCE formats are allowed for BC years.|reporterror=
- if given, an error message will be printed if no date is found in datestring.