Make sure all dates are in UTC (#1139)

pull/1138/head^2
Nabeel S 3 years ago committed by GitHub
parent 7e9eb08135
commit bfddb2c84d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -37,7 +37,7 @@ class DeletePireps extends Listener
*/ */
protected function deletePireps(int $expire_time_hours, int $state) 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(); $pireps = Pirep::where('created_at', '<', $dt)->where(['state' => $state])->get();
/** @var PirepService $pirepSvc */ /** @var PirepService $pirepSvc */

@ -25,7 +25,7 @@ class RemoveExpiredBids extends Listener
return; return;
} }
$date = Carbon::now()->subHours(setting('bids.expire_time')); $date = Carbon::now('UTC')->subHours(setting('bids.expire_time'));
Bid::where('created_at', '<', $date)->delete(); Bid::where('created_at', '<', $date)->delete();
} }
} }

@ -26,7 +26,7 @@ class RemoveExpiredLiveFlights extends Listener
return; return;
} }
$date = Carbon::now()->subHours(setting('acars.live_time')); $date = Carbon::now('UTC')->subHours(setting('acars.live_time'));
Pirep::where('updated_at', '<', $date) Pirep::where('updated_at', '<', $date)
->where('state', PirepState::IN_PROGRESS) ->where('state', PirepState::IN_PROGRESS)
->delete(); ->delete();

@ -1,17 +1,20 @@
<?php <?php
use App\Models\Journal;
use Carbon\Carbon;
use Faker\Generator as Faker; use Faker\Generator as Faker;
use Ramsey\Uuid\Uuid;
$factory->define(App\Models\JournalTransactions::class, function (Faker $faker) { $factory->define(App\Models\JournalTransaction::class, function (Faker $faker) {
return [ return [
'transaction_group' => \Ramsey\Uuid\Uuid::uuid4()->toString(), 'transaction_group' => Uuid::uuid4()->toString(),
'journal_id' => function () { 'journal_id' => function () {
return factory(\App\Models\Journal::class)->create()->id; return factory(Journal::class)->create()->id;
}, },
'credit' => $faker->numberBetween(100, 10000), 'credit' => $faker->numberBetween(100, 10000),
'debit' => $faker->numberBetween(100, 10000), 'debit' => $faker->numberBetween(100, 10000),
'currency' => 'USD', 'currency' => 'USD',
'memo' => $faker->sentence(6), 'memo' => $faker->sentence(6),
'post_date' => \Carbon\Carbon::now(), 'post_date' => Carbon::now('UTC'),
]; ];
}); });

@ -186,7 +186,7 @@ class Journal extends Model
*/ */
public function getCurrentBalance() public function getCurrentBalance()
{ {
return $this->getBalanceOn(Carbon::now()); return $this->getBalanceOn(Carbon::now('UTC'));
} }
/** /**

@ -147,7 +147,7 @@ class JournalRepository extends Repository implements CacheableInterface
$journal->refresh(); $journal->refresh();
if (!$date) { if (!$date) {
$date = Carbon::now(); $date = Carbon::now('UTC');
} }
$credit = $this->getCreditBalanceBetween($date, $journal); $credit = $this->getCreditBalanceBetween($date, $journal);

@ -90,10 +90,10 @@ class SeederService extends Service
$data = file_get_contents(database_path('/seeds/modules.yml')); $data = file_get_contents(database_path('/seeds/modules.yml'));
$yml = Yaml::parse($data); $yml = Yaml::parse($data);
foreach ($yml as $module) { 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'); $count = DB::table('modules')->where('name', $module['name'])->count('name');
if ($count === 0) { if ($count === 0) {
$module['created_at'] = Carbon::now(); $module['created_at'] = Carbon::now('UTC');
DB::table('modules')->insert($module); DB::table('modules')->insert($module);
} else { } else {
DB::table('modules') DB::table('modules')

@ -290,7 +290,7 @@ class PirepService extends Service
public function findDuplicate(Pirep $pirep) public function findDuplicate(Pirep $pirep)
{ {
$minutes = setting('pireps.duplicate_check_time', 10); $minutes = setting('pireps.duplicate_check_time', 10);
$time_limit = Carbon::now()->subMinutes($minutes)->toDateTimeString(); $time_limit = Carbon::now('UTC')->subMinutes($minutes)->toDateTimeString();
$where = [ $where = [
'user_id' => $pirep->user_id, 'user_id' => $pirep->user_id,

@ -484,7 +484,7 @@ class PIREPTest extends TestCase
*/ */
$minutes = setting('pireps.duplicate_check_time') + 1; $minutes = setting('pireps.duplicate_check_time') + 1;
$pirep = factory(Pirep::class)->create([ $pirep = factory(Pirep::class)->create([
'created_at' => Carbon::now()->subMinutes($minutes)->toDateTimeString(), 'created_at' => Carbon::now('UTC')->subMinutes($minutes)->toDateTimeString(),
]); ]);
// This should find itself... // This should find itself...

Loading…
Cancel
Save