Leap year: Difference between revisions
Content added Content deleted
(→{{header|UNIX Shell}}: simplifying the bash version) |
imported>Andrade.fr.8 No edit summary |
||
Line 2,226: | Line 2,226: | ||
1996 2000</syntaxhighlight> |
1996 2000</syntaxhighlight> |
||
=={{header|Koka}}== |
|||
Chain of boolean expressions |
|||
<syntaxhighlight lang="koka"> |
|||
pub fun is-leap-year(year: int) |
|||
year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)</syntaxhighlight> |
|||
If-Then-Else |
|||
<syntaxhighlight lang="koka"> |
|||
pub fun is-leap-year'(year: int) |
|||
year % (if year % 100 == 0 then 400 else 4) == 0</syntaxhighlight> |
|||
This approach use the buit-in libraries to create the february 28th date and the adds a day to it, which if it's in a leap year the next day wil be the 29th. |
|||
<syntaxhighlight lang="koka"> import std/time |
|||
import std/time/date |
|||
import std/time/time |
|||
pub fun is-leap-year''(year: int) |
|||
Date(year, 2, 28).time.add-days(1).day == 29</syntaxhighlight> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
<syntaxhighlight lang="kotlin">fun isLeapYear(year: Int) = year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)</syntaxhighlight> |
<syntaxhighlight lang="kotlin">fun isLeapYear(year: Int) = year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)</syntaxhighlight> |