-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Making CakeTime display 'about X ago' when time passed is lower than acc... #1511
Conversation
👍 for |
return __d('cake', '%s ago', $relativeDate); | ||
if ($relativeDate) { | ||
return __d('cake', '%s ago', $relativeDate); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can spare the else statement as the if has a return inside
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lorenzo was faster :)
You should add a second test with the different direction (so that $backwards is false). |
@dereuromark It now says "in about an hour" for future times where timeTo is less than accuracy. |
This makes sense to me 👍 |
@ankr Squash it, please. Then it looks pretty much good to go. |
return __d('cake', 'about an hour ago'); | ||
} | ||
|
||
return __d('cake', 'about a %s ago', $fWord); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this effectively untranslatable? Is it going to produce:
hace un **year**
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correction, this will make it impossible to translate correctly (ignoring whether $fWord
is translated or not) in some/many languages, using spanish:
Hace aproximadamente un segundo
Hace aproximadamente un minuto
Hace aproximadamente una hora
Hace aproximadamente un dia
Hace aproximadamente un**a** semana
Hace aproximadamente un mes
Hace aproximadamente un año
I suggest to use the same kind of fixed strings as for hour in all cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use an array of intervals => their translated values to make the code shorter/easier to read
…accuracy Removing unnecessary else Also support 'about' times for future times Make 'about' times translateable in all languages
@@ -820,48 +820,76 @@ public static function timeAgoInWords($dateTime, $options = array()) { | |||
return __d('cake', 'on %s', date($format, $inSeconds)); | |||
} | |||
|
|||
$f = $accuracy['second']; | |||
$fWord = $accuracy['second']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just what the framework needed. Few $fWord
s .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL
This looks good to me 👍 |
Making CakeTime display 'about X ago' when time passed is lower than acc...
...uracy
This would produces an incorrect value:
CakeTime::timeAgoInWords(strtotime('-58 minutes'), array('accuracy' => 'hour'));
Old result: " ago" (notice empty space)
New result: "about an hour ago"