Jump to content

Template:Century name from decade or year: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
fixes
allow single-digit decades
 
(16 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<includeonly><!--
<includeonly><!--
# First check whether this is a year or a decade: YYYY or YYY0s
# First check whether this is a year or a decade: YYYY or YYY0s
# No regexes, so check separately for "debuts" and "endings"
# No regexes, so check separately for "YYYY" and "YYY0s"
# In each case, the find function returns 0 for a nomatch, and 1 for a match,
# In each case, the find function returns 0 for a nomatch, and 1 for a match,
# so we add the two together and take a total of 0 as an error
# so we add the two together and take a total of 0 as an error
-->{{#ifeq: {{#expr: {{#invoke:String|find|{{{1|}}}|^%d%d%d%d$|plain=false}} + <!--
-->{{#ifeq: {{#expr: {{#invoke:String|find|{{{1|}}}|^%s*%d?%d?%d?%d%s*$|plain=false}} + <!--
-->{{#invoke:String|find|{{{1|}}}|^%d%d%d0s$|plain=false}} }}<!--
-->{{#invoke:String|find|{{{1|}}}|^%s*%d?%d?%d?0s%s*$|plain=false}} }}<!--
-->|0<!--
-->|0<!--
-->|<!--
-->|<!--
# Doesn't match, so do nothing
# Doesn't match, so do nothing unless the "nomatch" parameter is set
-->{{#if: {{{nomatch|}}}<!--
-->|{{{nomatch|}}}<!--
-->}}<!--
-->|<!--
-->|<!--
# We have a match
# We have a match
# Years and decades need different calculations
# Years and decades need different calculations
-->{{#ifeq: {{#invoke:String|match|{{{1|}}}|^%d%d%d%ds$|1|1|false|%%NOMATCH%%}}|%%NOMATCH%%<!--
-->{{#ifeq: {{#invoke:String|match|{{{1|}}}|^%s*%d?%d?%d?%ds%s*$|1|1|false|%%NOMATCH%%}}|%%NOMATCH%%<!--
-->|<!--
-->|<!--
# It's a year
# It's a year
-->{{Ordinal|{{#expr: 1 + floor(({{{1|}}} + 1) / 100)}}}}<!--
-->{{Ordinal|{{#expr: 1 + floor(({{{1|}}} - 1) / 100)}}}}<!--
-->|<!--
-->|<!--
# It's a decade
# It's a decade
-->{{Ordinal|{{#expr: 1 + floor(({{#invoke:String|replace|{{{1|}}}|s$||1|false}} + 5) / 100)}}}}<!--
-->{{Ordinal|{{#expr: 1 + floor(({{#invoke:String|replace|{{{1|}}}|^%s*(%d?%d?%d?0)s%s*$|%1|1|false}} + 5) / 100)}}}}<!--
-->}}<!--
-->}}<!--


# Now use a dash if the "dash" parameter is set to yes, true, or 1
# Now use a dash if the "dash" parameter is set to yes, true, or 1
-->{{#switch: {{lc: {{{dash|}}}}}<!--
-->{{#ifeq: {{{2|}}}|dash<!--
-->|1<!--
-->|&#45;<!-- Dash
-->|true<!--
-->|&#32;<!-- Space
-->|y<!--
-->|yes=&#45;<!--
-->|#default=&#32;<!--
-->}}<!--
-->}}<!--
-->century<!--
-->century<!--
-->}}</includeonly><noinclude></noinclude>
-->}}</includeonly><noinclude>
{{Documentation}}</noinclude>

Latest revision as of 16:53, 8 May 2020