This site is supported by donations to The OEIS Foundation.

Template:Ifleapyear

From OeisWiki
(Redirected from Template:If leap year)
Jump to: navigation, search

The {{ifleapyear}} or {{if leap year}} date and time if-then-else function template returns {{{2| 1 }}} if {{{1| {{LOCALYEAR}} }}} is a leap year, otherwise returns {{{3| 0 }}}. In plain English, returns second parameter (defaults to 1) if first parameter (defaults to local year of OEIS Wiki server) is a leap year, otherwise returns third parameter (defaults to 0.)

The {{is leap year}} date and time predicate function template returns 1 (if true) or 0 (if false.)

Years from 1 AD to 10000 AD are considered, while BC years are not considered. Note that there was no year 0, since the ancient Greeks and Romans had no concept of zero. Abides by the following two calendars

  • Julian calendar from 1 to 1581 (in 46 BC, Julius Caesar reformed the Roman calendar with leap years (given by a simple rule,) but many errors were committed and corrections applied until year 4 AD inclusive; The UNIX command cal incorrectly lists 4 AD as a leap year (Vardi 1991);)
  • Gregorian calendar from 1582 to 10000 (in 1582, Pope Gregory XIII decreed that the day after October 4, 1582 would be October 15, 1582. He also decreed a more sophisticated rule for determining leap years.)

Julian calendar

(...)

Gregorian calendar

In the Gregorian calendar, the current standard calendar in most of the world, most years that are evenly divisible by 4 are leap years. In each leap year, the month of February has 29 days instead of 28. Adding an extra day to the calendar every four years compensates for the fact that a period of 365 days is shorter than a solar year by almost 6 hours.

Some exceptions to this rule are required since the duration of a solar year is slightly less than 365.25 days. Years that are evenly divisible by 100 are not leap years, unless they are also evenly divisible by 400, in which case they are leap years.[1][2] For example, 1600 and 2000 were leap years, but 1700, 1800 and 1900 were not. Similarly, 2100, 2200, 2300, 2500, 2600, 2700, 2900 and 3000 will not be leap years, but 2400 and 2800 will be. By this rule, the average number of days per year will be 365 + 1/4 − 1/100 + 1/400 = 365.2425, which is 365 days, 5 hours, 49 minutes, and 12 seconds. The Gregorian calendar was designed to keep the vernal equinox[3] on or close to March 21, so that the date of Easter (celebrated on the Sunday after the 14th day of the Moon – i.e. a full moon – that falls on or after March 21) remains correct with respect to the vernal equinox.[4] The vernal equinox year is about 365.242374 days long (and increasing).

The marginal difference of 0.000125 days between the Gregorian calendar average year and the actual year means that, in 8,000 years, the calendar will be about one day behind where it is now. But in 8,000 years, the length of the vernal equinox year will have changed by an amount that cannot be accurately predicted (see below). Therefore, the current Gregorian calendar suffices for practical purposes, and the correction suggested by John Herschel of making 4000 a non-leap year will probably not be necessary.

Usage

{{ifleapyear|year in [1..10000] as input|output if true (optional, default: 1)|output if false (optional, default: 0)}}

or

{{ifleapyear|year in [1..10000] as input}} which returns 1 if true, 0 otherwise

or

{{ifleapyear}} where year defaults to local year of OEIS Wiki server, and which returns 1 if true, 0 otherwise

or

{{ifleapyear|2=output if true|3=output if false}} where year defaults to local year of OEIS Wiki server

Examples

Examples with valid input

code result
{{ifleapyear|1|leap year|common year}} common year
{{ifleapyear|4|leap year|common year}} common year
{{ifleapyear|8|leap year|common year}} leap year
{{ifleapyear|10.00|leap year|common year}} common year
{{ifleapyear|12|leap year|common year}} leap year
{{ifleapyear|400|leap year|common year}} leap year
{{ifleapyear|500|leap year|common year}} leap year
{{ifleapyear|504|leap year|common year}} leap year
{{ifleapyear|+1000|leap year|common year}} leap year
{{ifleapyear|1580|leap year|common year}} leap year
{{ifleapyear|1600|leap year|common year}} leap year
{{ifleapyear|1700|leap year|common year}} common year
{{ifleapyear|1704|leap year|common year}} leap year
{{ifleapyear|1960|leap year|common year}} leap year
{{ifleapyear}} 1
{{ifleapyear|2=leap year|3=common year}} leap year
{{ifleapyear|1900|leap year|common year}} common year
{{ifleapyear|1904}} 1
{{ifleapyear|1904|leap year|common year}} leap year
{{ifleapyear|2000|leap year|common year}} leap year
{{ifleapyear|2012|leap year|common year}} leap year


Examples with invalid input

code result
{{ifleapyear|one}} Ifleapyear error: Year must be a non formatted integer
{{ifleapyear|one|leap year|common year}} Ifleapyear error: Year must be a non formatted integer
{{ifleapyear|99 balloons|leap year|common year}} Ifleapyear error: Year must be a non formatted integer
{{ifleapyear|99.9999e-10|leap year|common year}} Ifleapyear error: Year must be a non formatted integer
{{ifleapyear|1,000.50|leap year|common year}} Ifleapyear error: Year must be a non formatted integer
{{ifleapyear|1,000|leap year|common year}} Ifleapyear error: Year must be a non formatted integer
{{ifleapyear|-34|leap year|common year}} Ifleapyear error: Year must be an integer in [1..10000]
{{ifleapyear|0|leap year|common year}} Ifleapyear error: Year must be an integer in [1..10000]
{{ifleapyear|-0|leap year|common year}} Ifleapyear error: Year must be an integer in [1..10000]
{{ifleapyear|99.9999e10|leap year|common year}} Ifleapyear error: Year must be an integer in [1..10000]
{{ifleapyear|99.9999E10|leap year|common year}} Ifleapyear error: Year must be an integer in [1..10000]
{{ifleapyear|-99.9999e+10|leap year|common year}} Ifleapyear error: Year must be an integer in [1..10000]

Test

Cf. {{ifleapyear/test}}

Code

Cf. {{ifleapyear/test#Code}}

See also

  • {{daynum}} gives the weekday number (0 to 6) for (Sun to Sat)
  • {{day}} gives the standard three letter weekday abbreviation.
  • {{fullday}} gives the full weekday name.


  • {{monthnum}} gives the month number (padded left with 0 if necessary to get two decimal digits) (01 to 12)
  • {{month}} gives the standard three letter month abbreviation.
  • {{fullmonth}} gives the full month name.
  • {{days in month}} (or {{monthdays}}) gives the number of days in a month (for any year from 1 AD to 10000 AD)


  • {{yearday}} returns the day of year from year, month and monthday (for any year from 1 AD to 10000 AD)
  • {{ifleapyear}} or {{if leap year}} returns different values depending on whether a given year is a leap year or a common year (for any year from 1 AD to 10000 AD)
  • {{is leap year}} predicate function template returns 1 (if true) or 0 (if false) depending on whether a given year is a leap year or a common year (for any year from 1 AD to 10000 AD)
  • {{Century}} returns the century for any nonzero (negative or positive) year
  • {{Millennium}} returns the millennium for any nonzero (negative or positive) year


  • {{to day of CE}} returns the day of CE (Christ Era) from year, month and monthday (for any year from 1 AD to 10000 AD)
  • {{from day of CE}} returns year, month and monthday (for any year from 1 AD to 10000 AD) from the day of CE (Christ Era)


  • {{date}} for date mathematics (for any year from 1 AD to 10000 AD) (returns the date offset a specified number of days from a given date)
  • {{days between}} for date mathematics (for any years from 1 AD to 10000 AD) (returns the number of days between two dates)

Notes

  1. Royal Observatory Greenwich, Leap years and leap seconds (2002). ROG learning team.
  2. United States Naval Observatory, Leap Years.
  3. Royal Observatory Greenwich, Equinoxes and solstices (2003). ROG learning team.
  4. E.G. Richards, E.G. (1998). Mapping time: The calendar and its history. Oxford University Press. p. 240. ISBN 0-19-286205-7.

External links