Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move out HTML logic to Helper/TimeHelper.php. The Utility/CakeTime.ph…

…p timeAgoInWords() now returns a string with the time, while the same function in Helper/TimeHelper.php may return an HTML element.
  • Loading branch information...
commit 352fbde2ec29cd869a766687f772de0de217bc33 1 parent 9fa531d
Magnus Johansson authored markstory committed
Showing with 47 additions and 27 deletions.
  1. +0 −26 lib/Cake/Utility/CakeTime.php
  2. +47 −1 lib/Cake/View/Helper/TimeHelper.php
26 lib/Cake/Utility/CakeTime.php
View
@@ -666,7 +666,6 @@ public static function timeAgoInWords($dateTime, $options = array()) {
$timezone = null;
$format = self::$wordFormat;
$end = self::$wordEnd;
- $element = null;
$accuracy = self::$wordAccuracy;
if (is_array($options)) {
@@ -686,24 +685,6 @@ public static function timeAgoInWords($dateTime, $options = array()) {
}
}
- if (isset($options['element'])) {
- $element_options = array(
- 'tag' => 'span',
- 'class' => 'timeAgoInWords',
- 'title' => $dateTime
- );
- if (is_array($options['element'])) {
- $element = array_merge($element_options, $options['element']);
- } else {
- if ($options['element']) {
- $element = $element_options;
- $element['tag'] = $options['element'];
- } else {
- $element = null;
- }
- }
- }
-
if (isset($options['format'])) {
$format = $options['format'];
unset($options['format']);
@@ -850,13 +831,6 @@ public static function timeAgoInWords($dateTime, $options = array()) {
$relativeDate = __d('cake', 'just now', 'just now');
}
- // Apply HTML element
- if ($element) {
- $title = isset($element['title']) ? ' title="'.$element['title'].'"' : '';
- $class = isset($element['class']) ? ' class="'.$element['class'].'"' : '';
- $relativeDate = '<'.$element['tag'].''.$title.$class.'>'.$relativeDate.'</'.$element['tag'].'>';
- }
-
return $relativeDate;
}
48 lib/Cake/View/Helper/TimeHelper.php
View
@@ -349,7 +349,39 @@ public function toRSS($dateString, $timezone = null) {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function timeAgoInWords($dateTime, $options = array()) {
- return $this->_engine->timeAgoInWords($dateTime, $options);
+ $element = null;
+
+ $stringDate = '';
+
+ if (isset($options['element'])) {
+ $element_options = array(
+ 'tag' => 'span',
+ 'class' => 'time-ago-in-words',
+ 'title' => $dateTime
+ );
+
+ if (is_array($options['element'])) {
+ $element = array_merge($element_options, $options['element']);
+ } else {
+ if ($options['element']) {
+ $element = $element_options;
+ $element['tag'] = $options['element'];
+ } else {
+ $element = null;
+ }
+ }
+ }
+
+ $relativeDate = $this->_engine->timeAgoInWords($dateTime, $options);
+
+ // Apply HTML element
+ if ($element) {
+ $title = isset($element['title']) ? ' title="'.$element['title'].'"' : '';
+ $class = isset($element['class']) ? ' class="'.$element['class'].'"' : '';
+ $relativeDate = '<'.$element['tag'].$title.$class.'>'.$relativeDate.'</'.$element['tag'].'>';
+ }
+
+ return $relativeDate;
}
/**
@@ -365,6 +397,20 @@ public function timeAgoInWords($dateTime, $options = array()) {
public function wasWithinLast($timeInterval, $dateString, $timezone = null) {
return $this->_engine->wasWithinLast($timeInterval, $dateString, $timezone);
}
+
+/**
+ * @see CakeTime::isWithinLast()
+ *
+ * @param mixed $timeInterval the numeric value with space then time type.
+ * Example of valid types: 6 hours, 2 days, 1 minute.
+ * @param mixed $dateString the datestring or unix timestamp to compare
+ * @param mixed $timezone User's timezone string or DateTimeZone object
+ * @return boolean
+ * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
+ */
+ public function isWithinNext($timeInterval, $dateString, $timezone = null) {
+ return $this->_engine->isWithinNext($timeInterval, $dateString, $timezone);
+ }
/**
* @see CakeTime::gmt()
Please sign in to comment.
Something went wrong with that request. Please try again.