From bfddb2c84d82a38f0d31358afc650317ccb69f29 Mon Sep 17 00:00:00 2001 From: Nabeel S Date: Tue, 13 Apr 2021 09:25:38 -0400 Subject: [PATCH] Make sure all dates are in UTC (#1139) --- app/Cron/Hourly/DeletePireps.php | 2 +- app/Cron/Hourly/RemoveExpiredBids.php | 2 +- app/Cron/Hourly/RemoveExpiredLiveFlights.php | 2 +- app/Database/factories/JournalTransactionsFactory.php | 11 +++++++---- app/Models/Journal.php | 2 +- app/Repositories/JournalRepository.php | 2 +- app/Services/Installer/SeederService.php | 4 ++-- app/Services/PirepService.php | 2 +- tests/PIREPTest.php | 2 +- 9 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/Cron/Hourly/DeletePireps.php b/app/Cron/Hourly/DeletePireps.php index 8e7e21fc..df199e59 100644 --- a/app/Cron/Hourly/DeletePireps.php +++ b/app/Cron/Hourly/DeletePireps.php @@ -37,7 +37,7 @@ class DeletePireps extends Listener */ protected function deletePireps(int $expire_time_hours, int $state) { - $dt = Carbon::now()->subHours($expire_time_hours); + $dt = Carbon::now('UTC')->subHours($expire_time_hours); $pireps = Pirep::where('created_at', '<', $dt)->where(['state' => $state])->get(); /** @var PirepService $pirepSvc */ diff --git a/app/Cron/Hourly/RemoveExpiredBids.php b/app/Cron/Hourly/RemoveExpiredBids.php index 7d8f80fc..3ace2c6f 100644 --- a/app/Cron/Hourly/RemoveExpiredBids.php +++ b/app/Cron/Hourly/RemoveExpiredBids.php @@ -25,7 +25,7 @@ class RemoveExpiredBids extends Listener return; } - $date = Carbon::now()->subHours(setting('bids.expire_time')); + $date = Carbon::now('UTC')->subHours(setting('bids.expire_time')); Bid::where('created_at', '<', $date)->delete(); } } diff --git a/app/Cron/Hourly/RemoveExpiredLiveFlights.php b/app/Cron/Hourly/RemoveExpiredLiveFlights.php index eff4b279..ed7c1adb 100644 --- a/app/Cron/Hourly/RemoveExpiredLiveFlights.php +++ b/app/Cron/Hourly/RemoveExpiredLiveFlights.php @@ -26,7 +26,7 @@ class RemoveExpiredLiveFlights extends Listener return; } - $date = Carbon::now()->subHours(setting('acars.live_time')); + $date = Carbon::now('UTC')->subHours(setting('acars.live_time')); Pirep::where('updated_at', '<', $date) ->where('state', PirepState::IN_PROGRESS) ->delete(); diff --git a/app/Database/factories/JournalTransactionsFactory.php b/app/Database/factories/JournalTransactionsFactory.php index 39bc18d8..d79a2c5b 100644 --- a/app/Database/factories/JournalTransactionsFactory.php +++ b/app/Database/factories/JournalTransactionsFactory.php @@ -1,17 +1,20 @@ define(App\Models\JournalTransactions::class, function (Faker $faker) { +$factory->define(App\Models\JournalTransaction::class, function (Faker $faker) { return [ - 'transaction_group' => \Ramsey\Uuid\Uuid::uuid4()->toString(), + 'transaction_group' => Uuid::uuid4()->toString(), 'journal_id' => function () { - return factory(\App\Models\Journal::class)->create()->id; + return factory(Journal::class)->create()->id; }, 'credit' => $faker->numberBetween(100, 10000), 'debit' => $faker->numberBetween(100, 10000), 'currency' => 'USD', 'memo' => $faker->sentence(6), - 'post_date' => \Carbon\Carbon::now(), + 'post_date' => Carbon::now('UTC'), ]; }); diff --git a/app/Models/Journal.php b/app/Models/Journal.php index bbfce96c..136beb6c 100644 --- a/app/Models/Journal.php +++ b/app/Models/Journal.php @@ -186,7 +186,7 @@ class Journal extends Model */ public function getCurrentBalance() { - return $this->getBalanceOn(Carbon::now()); + return $this->getBalanceOn(Carbon::now('UTC')); } /** diff --git a/app/Repositories/JournalRepository.php b/app/Repositories/JournalRepository.php index 1758a292..73c65700 100644 --- a/app/Repositories/JournalRepository.php +++ b/app/Repositories/JournalRepository.php @@ -147,7 +147,7 @@ class JournalRepository extends Repository implements CacheableInterface $journal->refresh(); if (!$date) { - $date = Carbon::now(); + $date = Carbon::now('UTC'); } $credit = $this->getCreditBalanceBetween($date, $journal); diff --git a/app/Services/Installer/SeederService.php b/app/Services/Installer/SeederService.php index 3ddfd9d0..e3fc4adc 100644 --- a/app/Services/Installer/SeederService.php +++ b/app/Services/Installer/SeederService.php @@ -90,10 +90,10 @@ class SeederService extends Service $data = file_get_contents(database_path('/seeds/modules.yml')); $yml = Yaml::parse($data); foreach ($yml as $module) { - $module['updated_at'] = Carbon::now(); + $module['updated_at'] = Carbon::now('UTC'); $count = DB::table('modules')->where('name', $module['name'])->count('name'); if ($count === 0) { - $module['created_at'] = Carbon::now(); + $module['created_at'] = Carbon::now('UTC'); DB::table('modules')->insert($module); } else { DB::table('modules') diff --git a/app/Services/PirepService.php b/app/Services/PirepService.php index 666c2810..dfe20394 100644 --- a/app/Services/PirepService.php +++ b/app/Services/PirepService.php @@ -290,7 +290,7 @@ class PirepService extends Service public function findDuplicate(Pirep $pirep) { $minutes = setting('pireps.duplicate_check_time', 10); - $time_limit = Carbon::now()->subMinutes($minutes)->toDateTimeString(); + $time_limit = Carbon::now('UTC')->subMinutes($minutes)->toDateTimeString(); $where = [ 'user_id' => $pirep->user_id, diff --git a/tests/PIREPTest.php b/tests/PIREPTest.php index 8c288bb3..2f52d0df 100644 --- a/tests/PIREPTest.php +++ b/tests/PIREPTest.php @@ -484,7 +484,7 @@ class PIREPTest extends TestCase */ $minutes = setting('pireps.duplicate_check_time') + 1; $pirep = factory(Pirep::class)->create([ - 'created_at' => Carbon::now()->subMinutes($minutes)->toDateTimeString(), + 'created_at' => Carbon::now('UTC')->subMinutes($minutes)->toDateTimeString(), ]); // This should find itself...