mirror of
https://github.com/openvk/openvk
synced 2024-12-23 00:51:03 +03:00
Make DateTime compatible with Windows
This commit is contained in:
parent
7be8b25a21
commit
b2f069f75f
3 changed files with 23 additions and 6 deletions
|
@ -25,24 +25,24 @@ class DateTime
|
||||||
|
|
||||||
if($this->timestamp >= strtotime("midnight")) { # Today
|
if($this->timestamp >= strtotime("midnight")) { # Today
|
||||||
if($diff->h >= 1)
|
if($diff->h >= 1)
|
||||||
return tr("time_today") . tr("time_at_sp") . strftime("%X", $this->timestamp);
|
return tr("time_today") . tr("time_at_sp") . ovk_strftime_safe("%X", $this->timestamp);
|
||||||
else if($diff->i < 2)
|
else if($diff->i < 2)
|
||||||
return tr("time_just_now");
|
return tr("time_just_now");
|
||||||
else
|
else
|
||||||
return $diff->i === 5 ? tr("time_exactly_five_minutes_ago") : tr("time_minutes_ago", $diff->i);
|
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 >= strtotime("-1day midnight")) { # Yesterday
|
||||||
return tr("time_yesterday") . tr("time_at_sp") . strftime("%X", $this->timestamp);
|
return tr("time_yesterday") . tr("time_at_sp") . ovk_strftime_safe("%X", $this->timestamp);
|
||||||
} else if(strftime("%G", $this->timestamp) === strftime("%G")) { # In this year
|
} else if(ovk_strftime_safe("%G", $this->timestamp) === ovk_strftime_safe("%G")) { # In this year
|
||||||
return strftime("%e %h ", $this->timestamp) . tr("time_at_sp") . strftime(" %R %p", $this->timestamp);
|
return ovk_strftime_safe("%e %h ", $this->timestamp) . tr("time_at_sp") . ovk_strftime_safe(" %R %p", $this->timestamp);
|
||||||
} else {
|
} else {
|
||||||
return strftime("%e %B %G ", $this->timestamp) . tr("time_at_sp") . strftime(" %X", $this->timestamp);
|
return ovk_strftime_safe("%e %B %G ", $this->timestamp) . tr("time_at_sp") . ovk_strftime_safe(" %X", $this->timestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function format(string $format, bool $useDate = false): string
|
function format(string $format, bool $useDate = false): string
|
||||||
{
|
{
|
||||||
if(!$useDate)
|
if(!$useDate)
|
||||||
return strftime($format, $this->timestamp);
|
return ovk_strftime_safe($format, $this->timestamp);
|
||||||
else
|
else
|
||||||
return date($format, $this->timestamp);
|
return date($format, $this->timestamp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,6 +121,22 @@ function ovk_proc_strtrim(string $string, int $length = 0): string
|
||||||
return ovk_proc_strtr($string, $length);
|
return ovk_proc_strtr($string, $length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ovk_strftime_safe(string $format, ?int $timestamp = NULL): string
|
||||||
|
{
|
||||||
|
$str = strftime($format, $timestamp ?? time());
|
||||||
|
if(PHP_SHLIB_SUFFIX === "dll") {
|
||||||
|
$enc = tr("__WinEncoding");
|
||||||
|
if($enc === "@__WinEncoding")
|
||||||
|
$enc = "Windows-1251";
|
||||||
|
|
||||||
|
$nStr = iconv($enc, "UTF-8", $str);
|
||||||
|
if(!is_null($nStr))
|
||||||
|
$str = $nStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
return (function() {
|
return (function() {
|
||||||
_ovk_check_environment();
|
_ovk_check_environment();
|
||||||
require __DIR__ . "/vendor/autoload.php";
|
require __DIR__ . "/vendor/autoload.php";
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"__locale" = "ru_UA.utf8;ru_RU.UTF-8;Rus";
|
"__locale" = "ru_UA.utf8;ru_RU.UTF-8;Rus";
|
||||||
|
"__WinEncoding" = "Windows-1251";
|
||||||
|
|
||||||
%{ Check for https://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html %}
|
%{ Check for https://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html %}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue