2005-05-15 21:41:38 +00:00
|
|
|
<?PHP
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// + $Id$
|
|
|
|
// +------------------------------------------------------------------+ //
|
2005-05-16 00:52:42 +00:00
|
|
|
// + Cake <https://developers.nextco.com/cake/> + //
|
|
|
|
// + Copyright: (c) 2005 Cake Authors/Developers + //
|
2005-05-15 21:41:38 +00:00
|
|
|
// + + //
|
2005-05-16 00:52:42 +00:00
|
|
|
// + Author(s): Michal Tatarynowicz aka Pies <tatarynowicz@gmail.com> + //
|
|
|
|
// + Larry E. Masters aka PhpNut <nut@phpnut.com> + //
|
|
|
|
// + Kamil Dzielinski aka Brego <brego.dk@gmail.com> + //
|
2005-05-15 21:41:38 +00:00
|
|
|
// + + //
|
|
|
|
// +------------------------------------------------------------------+ //
|
2005-05-16 00:52:42 +00:00
|
|
|
// + Licensed under The MIT License + //
|
|
|
|
// + Redistributions of files must retain the above copyright notice. + //
|
|
|
|
// + You may not use this file except in compliance with the License. + //
|
|
|
|
// + + //
|
|
|
|
// + You may obtain a copy of the License at: + //
|
|
|
|
// + License page: http://www.opensource.org/licenses/mit-license.php + //
|
2005-05-15 21:41:38 +00:00
|
|
|
// +------------------------------------------------------------------+ //
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Purpose: Time
|
|
|
|
* Time related functions, formatting for dates etc.
|
|
|
|
*
|
|
|
|
* @filesource
|
|
|
|
* @author Michal Tatarynowicz <tatarynowicz@gmail.com>
|
2005-05-16 00:52:42 +00:00
|
|
|
* @author Larry E. Masters aka PhpNut <nut@phpnut.com>
|
|
|
|
* @author Kamil Dzielinski aka Brego <brego.dk@gmail.com>
|
|
|
|
* @copyright Copyright (c) 2005, Cake Authors/Developers
|
|
|
|
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
|
2005-05-15 21:41:38 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.libs
|
|
|
|
* @since Cake v 0.2.9
|
|
|
|
* @version $Revision$
|
2005-05-16 00:52:42 +00:00
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
2005-05-15 21:41:38 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
uses ('object');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.libs
|
|
|
|
* @since Cake v 0.2.9
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class Time extends Object {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param unknown_type $date_string
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2005-05-16 23:14:37 +00:00
|
|
|
function nice ($date_string=null) {
|
|
|
|
$date = $date_string? strtotime($date_string): time();
|
|
|
|
return date("D, M jS Y, H:i", $date);
|
|
|
|
}
|
2005-05-15 21:41:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param unknown_type $date_string
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2005-05-16 23:14:37 +00:00
|
|
|
function niceShort ($date_string=null) {
|
|
|
|
$date = $date_string? Time::fromString($date_string): time();
|
2005-05-15 21:41:38 +00:00
|
|
|
|
2005-05-16 23:14:37 +00:00
|
|
|
$y = Time::isThisYear($date)? '': ' Y';
|
2005-05-15 21:41:38 +00:00
|
|
|
|
2005-05-16 23:14:37 +00:00
|
|
|
if (Time::isToday($date))
|
|
|
|
return "Today, ".date("H:i", $date);
|
|
|
|
elseif (Time::wasYesterday($date))
|
|
|
|
return "Yesterday, ".date("H:i", $date);
|
|
|
|
else
|
|
|
|
return date("M jS{$y}, H:i", $date);
|
|
|
|
}
|
2005-05-15 21:41:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param unknown_type $date
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2005-05-16 23:14:37 +00:00
|
|
|
function isToday ($date) {
|
|
|
|
return date('Y-m-d', $date) == date('Y-m-d', time());
|
|
|
|
}
|
2005-05-15 21:41:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param unknown_type $date
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2005-05-16 23:14:37 +00:00
|
|
|
function isThisYear ($date) {
|
|
|
|
return date('Y', $date) == date('Y', time());
|
|
|
|
}
|
2005-05-15 21:41:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param unknown_type $date
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2005-05-16 23:14:37 +00:00
|
|
|
function wasYesterday ($date) {
|
|
|
|
return date('Y-m-d', $date) == date('Y-m-d', strtotime('yesterday'));
|
|
|
|
}
|
2005-05-15 21:41:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param unknown_type $date_string
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2005-05-16 23:14:37 +00:00
|
|
|
function fromString ($date_string) {
|
|
|
|
return strtotime($date_string);
|
|
|
|
}
|
2005-05-15 21:41:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|