From 0cd1397ab1d4d3e82ecd82ecbb7a97d44ef7fec0 Mon Sep 17 00:00:00 2001 From: themohooks <81331307+themohooks@users.noreply.github.com> Date: Thu, 18 Jul 2024 19:09:32 +0300 Subject: [PATCH] fixes --- app/Controllers/Api/Images/Upload.php | 2 +- app/Services/Date.php | 55 ++++++++++++++++++--------- views/components/Navbar.php | 13 +++++-- 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/app/Controllers/Api/Images/Upload.php b/app/Controllers/Api/Images/Upload.php index a42cb24..e8bbd58 100644 --- a/app/Controllers/Api/Images/Upload.php +++ b/app/Controllers/Api/Images/Upload.php @@ -27,7 +27,7 @@ class Upload } else { $moderated = 1; } - DB::query('INSERT INTO photos VALUES (\'0\', :userid, :postbody, :photourl, :time, :timeup, :exif, 0, :moderated, :place, :content)', array(':postbody' => $postbody, ':userid' => Auth::userid(), ':time' => mktime(0, 0, 0, $_POST['month'], $_POST['day'], $_POST['year']), ':content' => $content, ':photourl' => self::$photourl, ':exif' => $exif, ':place' => $_POST['place'], ':timeup'=>time(), ':moderated'=>$moderated)); + DB::query('INSERT INTO photos VALUES (\'0\', :userid, :postbody, :photourl, :time, :timeup, :exif, 0, :moderated, :place, 0, :content)', array(':postbody' => $postbody, ':userid' => Auth::userid(), ':time' => mktime(0, 0, 0, $_POST['month'], $_POST['day'], $_POST['year']), ':content' => $content, ':photourl' => self::$photourl, ':exif' => $exif, ':place' => $_POST['place'], ':timeup'=>time(), ':moderated'=>$moderated)); echo json_encode( array( 'id' => DB::query('SELECT id FROM photos ORDER BY id DESC LIMIT 1')[0]['id'], diff --git a/app/Services/Date.php b/app/Services/Date.php index 89c03b9..f37af41 100644 --- a/app/Services/Date.php +++ b/app/Services/Date.php @@ -8,31 +8,50 @@ class Date $currentTime = time(); $dateDiff = $currentTime - $date; if ($date != null) { - if ($dateDiff <= 1) { - return "только что"; - } elseif ($dateDiff <= 60) { - return $dateDiff . " секунд " . self::getAgoSuffix($dateDiff); - } elseif ($dateDiff <= 3600) { - $minutes = floor($dateDiff / 60); - return $minutes . " минут " . self::getAgoSuffix($minutes); - } elseif ($dateDiff <= 86400) { - $hours = floor($dateDiff / 3600); - return $hours . " часов " . self::getAgoSuffix($hours); - } else { - return self::formatDate($date); + if ($dateDiff <= 1) { + return "только что"; + } elseif ($dateDiff < 60) { + return $dateDiff . " секунд " . self::getAgoSuffix($dateDiff); + } elseif ($dateDiff < 3600) { + $minutes = floor($dateDiff / 60); + return $minutes . " " . self::getMinuteSuffix($minutes) . " " . self::getAgoSuffix($minutes); + } elseif ($dateDiff < 86400) { + $hours = floor($dateDiff / 3600); + return $hours . " " . self::getHourSuffix($hours) . " " . self::getAgoSuffix($hours); + } else { + return self::formatDate($date); + } } } - } private static function getAgoSuffix($value) + { + return "назад"; + } + + private static function getMinuteSuffix($value) { $lastDigit = $value % 10; - if ($lastDigit == 1 && $value != 11) { - return "назад"; - } elseif (($lastDigit == 2 || $lastDigit == 3 || $lastDigit == 4) && ($value < 10 || $value > 20)) { - return "назад"; + $lastTwoDigits = $value % 100; + if ($lastDigit == 1 && $lastTwoDigits != 11) { + return "минуту"; + } elseif (($lastDigit >= 2 && $lastDigit <= 4) && ($lastTwoDigits < 10 || $lastTwoDigits > 20)) { + return "минуты"; } else { - return "назад"; + return "минут"; + } + } + + private static function getHourSuffix($value) + { + $lastDigit = $value % 10; + $lastTwoDigits = $value % 100; + if ($lastDigit == 1 && $lastTwoDigits != 11) { + return "час"; + } elseif (($lastDigit >= 2 && $lastDigit <= 4) && ($lastTwoDigits < 10 || $lastTwoDigits > 20)) { + return "часа"; + } else { + return "часов"; } } diff --git a/views/components/Navbar.php b/views/components/Navbar.php index c1400aa..5b82110 100644 --- a/views/components/Navbar.php +++ b/views/components/Navbar.php @@ -1,6 +1,6 @@