Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Copying some of the old tests for TimeHelper
  • Loading branch information
lorenzo committed Apr 21, 2014
1 parent ef1df55 commit 7fc3522
Show file tree
Hide file tree
Showing 2 changed files with 366 additions and 84 deletions.
30 changes: 28 additions & 2 deletions src/View/Helper/TimeHelper.php
Expand Up @@ -67,6 +67,30 @@ public function isToday($dateString, $timezone = null) {
return (new Time($dateString, $timezone))->isToday();
}

/**
* Returns true if given datetime string is in the future.
*
* @param int|string|\DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string|\DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return bool True if datetime string is today
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
*/
public function isFuture($dateString, $timezone = null) {
return (new Time($dateString, $timezone))->isFuture();
}

/**
* Returns true if given datetime string is in the past.
*
* @param int|string|\DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string|\DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return bool True if datetime string is today
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
*/
public function isPast($dateString, $timezone = null) {
return (new Time($dateString, $timezone))->isPast();
}

/**
* Returns true if given datetime string is within this week.
*
Expand Down Expand Up @@ -167,7 +191,8 @@ public function toUnix($dateString, $timezone = null) {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function toAtom($dateString, $timezone = null) {
return (new Time($dateString, $timezone))->toATOMString();
$timezone = $timezone ?: date_default_timezone_get();
return (new Time($dateString))->timezone($timezone)->toATOMString();
}

/**
Expand All @@ -179,7 +204,8 @@ public function toAtom($dateString, $timezone = null) {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function toRSS($dateString, $timezone = null) {
return (new Time($dateString, $timezone))->toRSSString();
$timezone = $timezone ?: date_default_timezone_get();
return (new Time($dateString))->timezone($timezone)->toRSSString();
}

/**
Expand Down

0 comments on commit 7fc3522

Please sign in to comment.