Skip to content

Commit

Permalink
Simplifying the code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Apr 21, 2014
1 parent f7bb82f commit 499a26e
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions src/Utility/Time.php
Expand Up @@ -233,9 +233,14 @@ public function timeAgoInWords(array $options = []) {
$relativeString = __d('cake', '%s ago');
$absoluteString = __d('cake', 'on %s');
$accuracy = static::$wordAccuracy;
$from = static::now();
$opts = ['timezone', 'format', 'end', 'relativeString', 'absoluteString', 'from'];

if (isset($options['timezone'])) {
$timezone = $options['timezone'];
foreach ($opts as $option) {
if (isset($options[$option])) {
$$option = $options[$option];
unset($options[$option]);
}
}

if (isset($options['accuracy'])) {
Expand All @@ -248,25 +253,7 @@ public function timeAgoInWords(array $options = []) {
}
}

if (isset($options['format'])) {
$format = $options['format'];
}
if (isset($options['end'])) {
$end = $options['end'];
}
if (isset($options['relativeString'])) {
$relativeString = $options['relativeString'];
unset($options['relativeString']);
}
if (isset($options['absoluteString'])) {
$absoluteString = $options['absoluteString'];
unset($options['absoluteString']);
}

$now = empty($options['from']) ? static::now() : $options['from'];
unset($options['end'], $options['format'], $options['from']);

$now = $now->format('U');
$now = $from->format('U');
$inSeconds = $this->format('U');
$backwards = ($inSeconds > $now);

Expand Down

0 comments on commit 499a26e

Please sign in to comment.