From: Daniel Karbach Date: Sun, 12 Mar 2023 13:51:45 +0000 (+0100) Subject: slightly better way of fixing timezones X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=7b1cb93fccac286d4119eb308435dccc72a03811;p=alttp.git slightly better way of fixing timezones --- 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'); + }); + } +};