|
@@ -543,38 +543,45 @@ class Page
|
|
|
// $complete = false : short version
|
|
|
// $complete = true : full version
|
|
|
public function relativeTime($complete = false)
|
|
|
- {
|
|
|
- $current = new DateTime;
|
|
|
- $past = new DateTime($this->getValue('dateRaw'));
|
|
|
- $elapsed = $current->diff($past);
|
|
|
-
|
|
|
- $elapsed->w = floor($elapsed->d / 7);
|
|
|
- $elapsed->d -= $elapsed->w * 7;
|
|
|
-
|
|
|
- $string = array(
|
|
|
- 'y' => 'year',
|
|
|
- 'm' => 'month',
|
|
|
- 'w' => 'week',
|
|
|
- 'd' => 'day',
|
|
|
- 'h' => 'hour',
|
|
|
- 'i' => 'minute',
|
|
|
- 's' => 'second',
|
|
|
- );
|
|
|
-
|
|
|
- foreach ($string as $key => &$value) {
|
|
|
- if ($elapsed->$key) {
|
|
|
- $value = $elapsed->$key . ' ' . $value . ($elapsed->$key > 1 ? 's' : ' ');
|
|
|
- } else {
|
|
|
- unset($string[$key]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (!$complete) {
|
|
|
- $string = array_slice($string, 0, 1);
|
|
|
- }
|
|
|
-
|
|
|
- return $string ? implode(', ', $string) . ' ago' : 'Just now';
|
|
|
- }
|
|
|
+ {
|
|
|
+ $current = new DateTime;
|
|
|
+ $past = new DateTime($this->getValue('dateRaw'));
|
|
|
+ $elapsed = $current->diff($past);
|
|
|
+
|
|
|
+ // Calculate weeks separately
|
|
|
+ $weeks = floor($elapsed->d / 7);
|
|
|
+ $elapsed->d -= $weeks * 7;
|
|
|
+
|
|
|
+ $string = array(
|
|
|
+ 'y' => 'year',
|
|
|
+ 'm' => 'month',
|
|
|
+ 'w' => $weeks,
|
|
|
+ 'd' => 'day',
|
|
|
+ 'h' => 'hour',
|
|
|
+ 'i' => 'minute',
|
|
|
+ 's' => 'second',
|
|
|
+ );
|
|
|
+
|
|
|
+ foreach ($string as $key => &$value) {
|
|
|
+ if ($key == 'w') {
|
|
|
+ if ($weeks > 0) {
|
|
|
+ $value = $weeks . ' week' . ($weeks > 1 ? 's' : '');
|
|
|
+ } else {
|
|
|
+ unset($string[$key]);
|
|
|
+ }
|
|
|
+ } elseif ($elapsed->$key) {
|
|
|
+ $value = $elapsed->$key . ' ' . $value . ($elapsed->$key > 1 ? 's' : '');
|
|
|
+ } else {
|
|
|
+ unset($string[$key]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$complete) {
|
|
|
+ $string = array_slice($string, 0, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $string ? implode(', ', $string) . ' ago' : 'Just now';
|
|
|
+ }
|
|
|
|
|
|
// Returns the value from the field, false if the fields doesn't exists
|
|
|
// If you set the $option as TRUE, the function returns an array with all the values of the field
|