From 47c758c5c0bccd439e269f6f5bff3646df5b1e7a Mon Sep 17 00:00:00 2001 From: printempw Date: Wed, 18 Jan 2017 12:56:37 +0800 Subject: [PATCH] fix comparing time of signing in --- app/Models/User.php | 10 ++++++++-- app/Services/Utils.php | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 77223a66..afe9558c 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -304,9 +304,15 @@ class User extends Model public function getSignInRemainingTime() { // convert to timestamp - $lastSignInTime = strtotime($this->getLastSignInTime()); + $lastSignInTime = Carbon::parse($this->getLastSignInTime()); - return option('sign_after_zero') ? (Carbon::tomorrow()->timestamp - time()) : ($lastSignInTime + option('sign_gap_time') * 3600 - time()); + if (option('sign_after_zero')) { + return Carbon::now()->diffInSeconds( + (($lastSignInTime <= Carbon::today()) ? $lastSignInTime : Carbon::tomorrow()) + , false); + } + + return $lastSignInTime->addSeconds(option('sign_gap_time') * 3600)->diffInSeconds(Carbon::now()); } /** diff --git a/app/Services/Utils.php b/app/Services/Utils.php index 701999ba..d9d23a85 100644 --- a/app/Services/Utils.php +++ b/app/Services/Utils.php @@ -3,6 +3,7 @@ namespace App\Services; use Log; +use Carbon\Carbon; use Illuminate\Support\Str; use Storage as LaravelStorage; use App\Exceptions\PrettyPageException; @@ -209,7 +210,7 @@ class Utils public static function getTimeFormatted($timestamp = 0) { - return ($timestamp == 0) ? date('Y-m-d H:i:s') : date('Y-m-d H:i:s', $timestamp); + return ($timestamp == 0) ? Carbon::now()->toDateTimeString() : Carbon::createFromTimestamp($timestamp)->toDateTimeString(); } /**