mirror of
https://github.com/openvk/openvk
synced 2024-12-22 08:31:18 +03:00
fix(datetime): adjust to timezone
This commit is contained in:
parent
48ccd7ef43
commit
198bf7472d
1 changed files with 5 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\Web\Util;
|
||||
use Chandler\Session\Session;
|
||||
|
||||
class DateTime
|
||||
{
|
||||
|
@ -21,17 +22,19 @@ class DateTime
|
|||
$then = date_create("@" . $this->timestamp);
|
||||
$now = date_create();
|
||||
$diff = date_diff($now, $then);
|
||||
|
||||
$sessionOffset = intval(Session::i()->get("_timezoneOffset"));
|
||||
if($diff->invert === 0)
|
||||
return ovk_strftime_safe("%e %B %Y ", $this->timestamp) . tr("time_at_sp") . ovk_strftime_safe(" %R", $this->timestamp);
|
||||
|
||||
if($this->timestamp >= strtotime("midnight")) { # Today
|
||||
if(($this->timestamp + $sessionOffset) >= (strtotime("midnight") + $sessionOffset)) { # Today
|
||||
if($diff->h >= 1)
|
||||
return tr("time_today") . tr("time_at_sp") . ovk_strftime_safe(" %R", $this->timestamp);
|
||||
else if($diff->i < 2)
|
||||
return tr("time_just_now");
|
||||
else
|
||||
return $diff->i === 5 ? tr("time_exactly_five_minutes_ago") : tr("time_minutes_ago", $diff->i);
|
||||
} else if($this->timestamp >= strtotime("-1day midnight")) { # Yesterday
|
||||
} else if(($this->timestamp + $sessionOffset) >= (strtotime("-1day midnight") + $sessionOffset)) { # Yesterday
|
||||
return tr("time_yesterday") . tr("time_at_sp") . ovk_strftime_safe(" %R", $this->timestamp);
|
||||
} else if(ovk_strftime_safe("%Y", $this->timestamp) === ovk_strftime_safe("%Y", time())) { # In this year
|
||||
return ovk_strftime_safe("%e %h ", $this->timestamp) . tr("time_at_sp") . ovk_strftime_safe(" %R", $this->timestamp);
|
||||
|
|
Loading…
Reference in a new issue