Skip to content
Extraits de code Groupes Projets
Valider 524cc8eb rédigé par mattab's avatar mattab
Parcourir les fichiers

Merge branch 'master' of github.com:piwik/piwik

parents 11db442f 32f40ab9
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -289,6 +289,18 @@ class Date
return $this->getTimestamp() < $date->getTimestamp();
}
/**
* Returns `true` if the current year is a leap year, false otherwise.
*
* @return bool
*/
public function isLeapYear()
{
$currentYear = date('Y', $this->getTimestamp());
return ($currentYear % 400) == 0 || (($currentYear % 4) == 0 && ($currentYear % 100) != 0);
}
/**
* Converts this date to the requested string format. See {@link http://php.net/date}
* for the list of format strings.
......
......@@ -238,4 +238,31 @@ class DateTest extends PHPUnit_Framework_TestCase
$date = $date->subPeriod(5, 'year');
$this->assertEquals($dateExpected->getTimestamp(), $date->getTimestamp());
}
/**
* @group Core
*/
public function testIsLeapYear()
{
$date = Date::factory('2011-03-01');
$this->assertFalse($date->isLeapYear());
$date = Date::factory('2011-01-01');
$this->assertFalse($date->isLeapYear());
$date = Date::factory('2011-01-31');
$this->assertFalse($date->isLeapYear());
$date = Date::factory('2012-01-01');
$this->assertTrue($date->isLeapYear());
$date = Date::factory('2012-12-31');
$this->assertTrue($date->isLeapYear());
$date = Date::factory('2013-01-01');
$this->assertFalse($date->isLeapYear());
$date = Date::factory('2013-12-31');
$this->assertFalse($date->isLeapYear());
$date = Date::factory('2052-01-01');
$this->assertTrue($date->isLeapYear());
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter