Skip to content

Commit

Permalink
Removed Time::toServer(), it promoted bad practices
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Apr 21, 2014
1 parent ede3667 commit 5e441bf
Showing 1 changed file with 0 additions and 39 deletions.
39 changes: 0 additions & 39 deletions src/Utility/Time.php
Expand Up @@ -274,45 +274,6 @@ public static function toUnix() {
return $this->format('U');
}

/**
* Returns a formatted date in server's timezone.
*
* If a DateTime object is given or the dateString has a timezone
* segment, the timezone parameter will be ignored.
*
* If no timezone parameter is given and no DateTime object, the passed $dateString will be
* considered to be in the UTC timezone.
*
* @param int|string|\DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string|\DateTimeZone $timezone Timezone string or DateTimeZone object
* @param string $format date format string
* @return mixed Formatted date
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#TimeHelper::toServer
*/
public static function toServer($dateString, $timezone = null, $format = 'Y-m-d H:i:s') {
if ($timezone === null) {
$timezone = new \DateTimeZone('UTC');
} elseif (is_string($timezone)) {
$timezone = new \DateTimeZone($timezone);
} elseif (!($timezone instanceof \DateTimeZone)) {
return false;
}

if ($dateString instanceof \DateTime) {
$date = $dateString;
} elseif (is_int($dateString) || is_numeric($dateString)) {
$dateString = (int)$dateString;

$date = new \DateTime('@' . $dateString);
$date->setTimezone($timezone);
} else {
$date = new \DateTime($dateString, $timezone);
}

$date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
return $date->format($format);
}

/**
* Returns a date formatted for Atom RSS feeds.
*
Expand Down

0 comments on commit 5e441bf

Please sign in to comment.