Template:IsLeapYear

From OrthodoxWiki

Jump to: navigation, search

{{#expr: (((2008) mod 4 = 0) and ((2008) mod 100 != 0)) or ((2008) mod 400 = 0)}}


Usage:
{{IsLeapYear{{#if:year|

|year }}{{#if:| |{{{3}}} }}{{#if:| |{{{4}}} }}{{#if:| |{{{5}}} }}{{#if:| |... }}}}

year defaults to {{ CURRENTYEAR}} {{#ifeq: =|=|=|gives}} 2008

.

Formula:
{{#expr: ((({{{1}}}) mod 4 = 0) and (({{{1}}}) mod 100 != 0)) or (({{{1}}}) mod 400 = 0)}}
Use {{subst:IsLeapYear}} to get this code ready for optional substitution into another template.
Sanity check:
{{ IsLeapYear|2007{{#ifeq:+|-||||{{#ifeq:-|+|| }} }}}} {{#ifeq: +|-|{{{s}}}|gives}} {{#ifeq:-|+|{{#expr: (((2007) mod 4 = 0) and ((2007) mod 100 != 0)) or ((2007) mod 400 = 0)}}

|{{#ifeq:-|+|{{#expr: (((2007) mod 4 = 0) and ((2007) mod 100 != 0)) or ((2007) mod 400 = 0)}} |{{#expr: (((2007) mod 4 = 0) and ((2007) mod 100 != 0)) or ((2007) mod 400 = 0)}} }}}} , 2007 is no leap year.

{{ IsLeapYear|2008{{#ifeq:+|-||||{{#ifeq:-|+|| }} }}}} {{#ifeq: +|-|{{{s}}}|gives}} {{#ifeq:-|+|{{#expr: (((2008) mod 4 = 0) and ((2008) mod 100 != 0)) or ((2008) mod 400 = 0)}}

|{{#ifeq:-|+|{{#expr: (((2008) mod 4 = 0) and ((2008) mod 100 != 0)) or ((2008) mod 400 = 0)}} |{{#expr: (((2008) mod 4 = 0) and ((2008) mod 100 != 0)) or ((2008) mod 400 = 0)}} }}}} , 2008 is a leap year.

{{ IsLeapYear|2100{{#ifeq:+|-||||{{#ifeq:-|+|| }} }}}} {{#ifeq: +|-|{{{s}}}|gives}} {{#ifeq:-|+|{{#expr: (((2100) mod 4 = 0) and ((2100) mod 100 != 0)) or ((2100) mod 400 = 0)}}

|{{#ifeq:-|+|{{#expr: (((2100) mod 4 = 0) and ((2100) mod 100 != 0)) or ((2100) mod 400 = 0)}} |{{#expr: (((2100) mod 4 = 0) and ((2100) mod 100 != 0)) or ((2100) mod 400 = 0)}} }}}} , 2100 is no leap year.

{{ IsLeapYear|2400{{#ifeq:+|-||||{{#ifeq:-|+|| }} }}}} {{#ifeq: +|-|{{{s}}}|gives}} {{#ifeq:-|+|{{#expr: (((2400) mod 4 = 0) and ((2400) mod 100 != 0)) or ((2400) mod 400 = 0)}}

|{{#ifeq:-|+|{{#expr: (((2400) mod 4 = 0) and ((2400) mod 100 != 0)) or ((2400) mod 400 = 0)}} |{{#expr: (((2400) mod 4 = 0) and ((2400) mod 100 != 0)) or ((2400) mod 400 = 0)}} }}}} , 2400 is a leap year.

{{ IsLeapYear|1500{{#ifeq:+|-||||{{#ifeq:-|+|| }} }}}} {{#ifeq: +|-|{{{s}}}|gives}} {{#ifeq:-|+|{{#expr: (((1500) mod 4 = 0) and ((1500) mod 100 != 0)) or ((1500) mod 400 = 0)}}

|{{#ifeq:-|+|{{#expr: (((1500) mod 4 = 0) and ((1500) mod 100 != 0)) or ((1500) mod 400 = 0)}} |{{#expr: (((1500) mod 4 = 0) and ((1500) mod 100 != 0)) or ((1500) mod 400 = 0)}} }}}} , proleptic Gregorian calendar.

{{ IsLeapYear|-100{{#ifeq:+|-||||{{#ifeq:-|+|| }} }}}} {{#ifeq: +|-|{{{s}}}|gives}} {{#ifeq:-|+|{{#expr: (((-100) mod 4 = 0) and ((-100) mod 100 != 0)) or ((-100) mod 400 = 0)}}

|{{#ifeq:-|+|{{#expr: (((-100) mod 4 = 0) and ((-100) mod 100 != 0)) or ((-100) mod 400 = 0)}} |{{#expr: (((-100) mod 4 = 0) and ((-100) mod 100 != 0)) or ((-100) mod 400 = 0)}} }}}}

for 101 BC (mostly pointless).
{{ IsLeapYear|502*4-8{{#ifeq:+|-||||{{#ifeq:-|+|| }} }}}} {{#ifeq: +|-|{{{s}}}|gives}} {{#ifeq:-|+|{{#expr: (((502*4-8) mod 4 = 0) and ((502*4-8) mod 100 != 0)) or ((502*4-8) mod 400 = 0)}}

|{{#ifeq:-|+|{{#expr: (((502*4-8) mod 4 = 0) and ((502*4-8) mod 100 != 0)) or ((502*4-8) mod 400 = 0)}} |{{#expr: (((502*4-8) mod 4 = 0) and ((502*4-8) mod 100 != 0)) or ((502*4-8) mod 400 = 0)}} }}}} , guess why.

Results for fractions like {{ IsLeapYear|2000.9{{#ifeq:+|-||||{{#ifeq:-|+|| }} }}}} {{#ifeq: +|-|{{{s}}}|=}} {{#ifeq:-|+|{{#expr: (((2000.9) mod 4 = 0) and ((2000.9) mod 100 != 0)) or ((2000.9) mod 400 = 0)}} |{{#ifeq:-|+|{{#expr: (((2000.9) mod 4 = 0) and ((2000.9) mod 100 != 0)) or ((2000.9) mod 400 = 0)}} |{{#expr: (((2000.9) mod 4 = 0) and ((2000.9) mod 100 != 0)) or ((2000.9) mod 400 = 0)}} }}}}

are unspecified, even if it apparently gives an "expected" result at the moment this might change without notice.
Personal tools
pan-wiki Google Search