From 7b1cb93fccac286d4119eb308435dccc72a03811 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sun, 12 Mar 2023 14:51:45 +0100 Subject: [PATCH] slightly better way of fixing timezones --- app/Console/Commands/SyncSpeedGaming.php | 12 +++++-- .../2023_03_12_134350_event_timezone_fix.php | 32 +++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2023_03_12_134350_event_timezone_fix.php diff --git a/app/Console/Commands/SyncSpeedGaming.php b/app/Console/Commands/SyncSpeedGaming.php index b2ac7f1..ea09839 100644 --- a/app/Console/Commands/SyncSpeedGaming.php +++ b/app/Console/Commands/SyncSpeedGaming.php @@ -104,9 +104,15 @@ class SyncSpeedGaming extends Command { $episode->event()->associate($event); $episode->title = $sgEntry['match1']['title']; $start = Carbon::createFromFormat('Y-m-d\TH:i:sP', $sgEntry['when']); - // if speedgaming is in DST, it fucks up the timestamp - if (Carbon::now(new \DateTimeZone('America/Chicago'))->dst) { - $start->add(1, 'hour'); + if ($event->fix_timezone) { + $sg_zone = new \DateTimeZone('America/Chicago'); + $event_zone = new \DateTimeZone($event->fix_timezone); + // if speedgaming is in DST, it fucks up the timestamp + if (Carbon::createFromTimestamp($start->timestamp, $sg_zone)->dst && !Carbon::createFromTimestamp($start->timestamp, $event_zone)->dst) { + $start->add(1, 'hour'); + } else if (!Carbon::createFromTimestamp($start->timestamp, $sg_zone)->dst && Carbon::createFromTimestamp($start->timestamp, $event_zone)->dst) { + $start->sub(1, 'hour'); + } } if (!$episode->start || $start->ne($episode->start)) { $episode->start = $start; diff --git a/database/migrations/2023_03_12_134350_event_timezone_fix.php b/database/migrations/2023_03_12_134350_event_timezone_fix.php new file mode 100644 index 0000000..7ac8374 --- /dev/null +++ b/database/migrations/2023_03_12_134350_event_timezone_fix.php @@ -0,0 +1,32 @@ +string('fix_timezone')->default(''); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('events', function(Blueprint $table) { + $table->dropColumn('fix_timezone'); + }); + } +}; -- 2.39.2