isleapyear

function isleapyear( year ) --> res

Description

Checks if the given year is a leap year or not.

Parameters

year

The year that needs to be checked as number.

Return Values

res

true if the year is a leap year, otherwise false.

Code

--ZFUNC-isleapyear-v1
local function isleapyear( year ) --> res
   if( year % 4 == 0 and year % 100 ~= 0 ) or ( year % 400 == 0 ) then
      return true
   else
      return false
   end
end

return isleapyear

Examples

local t = require( "tapered" )
local isleapyear = require( "isleapyear" )

t.nok( isleapyear( 1900 ) )
t.nok( isleapyear( 2001 ) )
t.nok( isleapyear( 2002 ) )

t.ok( isleapyear( 2000 ) )
t.ok( isleapyear( 2004 ) )
t.ok( isleapyear( 2008 ) )

t.done()