Skip to content
Permalink
Browse files

Replace time() with DateTime's getTimestamp()

  • Loading branch information...
bcrowe committed Oct 30, 2013
1 parent 36f31c8 commit ed5539fe7d3b9691140daa27052b318e899f487e
Showing with 12 additions and 6 deletions.
  1. +12 −6 Cake/Utility/Time.php
@@ -136,7 +136,8 @@ public function __get($name) {
*/
public static function convertSpecifiers($format, $time = null) {
if (!$time) {
$time = time();
$dateTime = new \DateTime;
$time = $dateTime->getTimestamp();
}
static::$_time = $time;
return preg_replace_callback('/\%(\w+)/', array(__CLASS__, '_translateSpecifier'), $format);
@@ -356,7 +357,8 @@ public static function fromString($dateString, $timezone = null) {
*/
public static function nice($dateString = null, $timezone = null, $format = null) {
if (!$dateString) {
$dateString = time();
$dateTime = new \DateTime;
$dateString = $dateTime->getTimestamp();
}
$date = static::fromString($dateString, $timezone);
@@ -383,7 +385,8 @@ public static function nice($dateString = null, $timezone = null, $format = null
*/
public static function niceShort($dateString = null, $timezone = null) {
if (!$dateString) {
$dateString = time();
$dateTime = new \DateTime;
$dateString = $dateTime->getTimestamp();
}
$date = static::fromString($dateString, $timezone);
@@ -478,7 +481,8 @@ public static function isToday($dateString, $timezone = null) {
*/
public static function isFuture($dateString, $timezone = null) {
$timestamp = static::fromString($dateString, $timezone);
return $timestamp > time();
$dateTime = new \DateTime;
return $timestamp > $dateTime->getTimestamp();
}
/**
@@ -491,7 +495,8 @@ public static function isFuture($dateString, $timezone = null) {
*/
public static function isPast($dateString, $timezone = null) {
$timestamp = static::fromString($dateString, $timezone);
return $timestamp < time();
$dateTime = new \DateTime;
return $timestamp > $dateTime->getTimestamp();
}
/**
@@ -982,7 +987,8 @@ public static function isWithinNext($timeInterval, $dateString, $timezone = null
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#TimeHelper::gmt
*/
public static function gmt($dateString = null) {
$time = time();
$dateTime = new \DateTime;
$time = $dateTime->getTimestamp();
if ($dateString) {
$time = static::fromString($dateString);
}

0 comments on commit ed5539f

Please sign in to comment.
You can’t perform that action at this time.