wiclear-2007-07-19/inc/classes/date_helper.class.php
<?php
# ***** BEGIN LICENSE BLOCK *****
# This file is part of WiClear.
# Copyright (c) 2004-2007 David Jobet. All rights
# reserved.
#
# WiClear is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# WiClear is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with DotClear; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#
# ***** END LICENSE BLOCK *****
/**
* \brief helper class to deal with dates
*
* \todo create a date class as well to ease date operations
*/
class date_helper
{
/* \brief tells if a year is a leap year or not
*
* \param year possible leap year
* \return true if this is a leap year, false otherwise
*/
function isLeapYear($year)
{
return ($year % 4) == 0 &&
(
($year % 100) != 0 || ($year % 400) == 0
);
}
/* \brief returns number of days in a month
*
* \param month month to compute days
* \param year year of the month
* \return number of days in this particular month
*/
function daysInMonth($month, $year)
{
$nbDays = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
$month = $month % 12;
if ($month == 1)
{
// february : look if leap year
if (date_helper::isLeapYear($year))
{
return 29;
}
else
{
return 28;
}
}
return $nbDays[$month];
}
/**
* \brief returns date format to ISO 8601 standard (internal)
*
* \param value the value to convert to ISO 8601 format
* \return formatted date
*/
function getISO8601Date($value)
{
$timeOffset = date("O", $value);
$timeOffset = substr_replace($timeOffset, ':', 3, 0);
$date = date("Y-m-d\\TH:i:s", $value);
return $date.$timeOffset;
}
/**
* \brief returns date format to RFC 2822 standard (internal)
*
* \param value the value to convert to RFC 2822 format
* \return formatted date
*/
function getRFC2822Date($value)
{
$date = date("r", $value);
return $date;
}
}
?>