X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FUtil%2FTemporal.php;h=acafb66ab60538949a9b0cacd2540b19b2bc7382;hb=7e6ba0b4d271735bbf7474fb75a7cf43b787b678;hp=0186b59dd6157985d89128fa22f125981e95f8ad;hpb=08ead524339a43f29c809ca63514e40cd24dee9c;p=friendica.git
diff --git a/src/Util/Temporal.php b/src/Util/Temporal.php
index 0186b59dd6..acafb66ab6 100644
--- a/src/Util/Temporal.php
+++ b/src/Util/Temporal.php
@@ -1,6 +1,6 @@
get(local_user(), 'system', 'first_day_of_week', 0);
+ $firstDay = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'calendar', 'first_day_of_week', 0);
$lang = substr(DI::l10n()->getCurrentLang(), 0, 2);
@@ -305,27 +307,40 @@ class Temporal
* Results relative to current timezone.
* Limited to range of timestamps.
*
- * @param string $posted_date MySQL-formatted date string (YYYY-MM-DD HH:MM:SS)
- * @param string $format (optional) Parsed with sprintf()
- * %1$d %2$s ago, e.g. 22 hours ago, 1 minute ago
+ * @param string|null $posted_date MySQL-formatted date string (YYYY-MM-DD HH:MM:SS)
+ * @param bool $compare_time Compare date (false) or date and time (true). "true" is default.
+ * @param ClockInterface|null $clock
+ * %1$d %2$s ago, e.g. 22 hours ago, 1 minute ago
*
* @return string with relative date
*/
- public static function getRelativeDate(string $posted_date, string $format = null): string
+ public static function getRelativeDate(string $posted_date = null, bool $compare_time = true, ClockInterface $clock = null): string
{
- $localtime = $posted_date . ' UTC';
+ if (empty($posted_date) || $posted_date <= DBA::NULL_DATETIME) {
+ return DI::l10n()->t('never');
+ }
+ $clock = $clock ?? new SystemClock();
+
+ $localtime = $posted_date . ' UTC';
$abs = strtotime($localtime);
- if (is_null($posted_date) || $posted_date <= DBA::NULL_DATETIME || $abs === false) {
+ if ($abs === false) {
return DI::l10n()->t('never');
}
+ $now = $clock->now()->getTimestamp();
+
+ if (!$compare_time) {
+ $now = mktime(0, 0, 0, date('m', $now), date('d', $now), date('Y', $now));
+ $abs = mktime(0, 0, 0, date('m', $abs), date('d', $abs), date('Y', $abs));
+ }
+
$isfuture = false;
- $etime = time() - $abs;
+ $etime = $now - $abs;
- if ($etime < 1 && $etime >= 0) {
- return DI::l10n()->t('less than a second ago');
+ if ($etime >= 0 && $etime < 1) {
+ return $compare_time ? DI::l10n()->t('less than a second ago') : DI::l10n()->t('today');
}
if ($etime < 0){
@@ -346,15 +361,13 @@ class Temporal
foreach ($a as $secs => $str) {
$d = $etime / $secs;
if ($d >= 1) {
- $r = round($d);
+ $r = floor($d);
// translators - e.g. 22 hours ago, 1 minute ago
- if (!$format) {
- if($isfuture){
- $format = DI::l10n()->t('in %1$d %2$s');
- }
- else {
- $format = DI::l10n()->t('%1$d %2$s ago');
- }
+ if($isfuture){
+ $format = DI::l10n()->t('in %1$d %2$s');
+ }
+ else {
+ $format = DI::l10n()->t('%1$d %2$s ago');
}
return sprintf($format, $r, (($r == 1) ? $str[0] : $str[1]));