From f13b86527a8b52b14df665fcbd52aec66b5b0738 Mon Sep 17 00:00:00 2001 From: Corinna Hillebrand Date: Tue, 28 Oct 2025 19:05:18 +0100 Subject: [PATCH] Specify CEST Berlin timezone when parsing start and end dates of campaign --- public/index.php | 2 ++ src/Utils/CampaignConfigurationLoader.php | 4 ++-- tests/Unit/Utils/CampaignConfigurationLoaderTest.php | 10 ++++++++++ tests/bootstrap.php | 2 ++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/public/index.php b/public/index.php index bf1eee5..5fa1479 100644 --- a/public/index.php +++ b/public/index.php @@ -7,6 +7,8 @@ require __DIR__ . '/../vendor/autoload.php'; +date_default_timezone_set( 'Europe/Berlin' ); + // The check is to ensure we don't use .env in production if ( !isset( $_SERVER['APP_ENV'] ) && !isset( $_ENV['APP_ENV'] ) ) { if ( !class_exists( Dotenv::class ) ) { diff --git a/src/Utils/CampaignConfigurationLoader.php b/src/Utils/CampaignConfigurationLoader.php index da7962a..bf12e4f 100644 --- a/src/Utils/CampaignConfigurationLoader.php +++ b/src/Utils/CampaignConfigurationLoader.php @@ -95,8 +95,8 @@ private function buildCampaignFromData( string $campaignName, array $campaignDat return new Campaign( $campaignName, - new \DateTime( $start ), - new \DateTime( $end ), + new \DateTime( $start, new \DateTimeZone( 'Europe/Berlin' ) ), + new \DateTime( $end, new \DateTimeZone( 'Europe/Berlin' ) ), $trafficLimit, $category, new SystemRandomIntegerGenerator(), diff --git a/tests/Unit/Utils/CampaignConfigurationLoaderTest.php b/tests/Unit/Utils/CampaignConfigurationLoaderTest.php index 3100f46..3ea9a8e 100644 --- a/tests/Unit/Utils/CampaignConfigurationLoaderTest.php +++ b/tests/Unit/Utils/CampaignConfigurationLoaderTest.php @@ -47,6 +47,16 @@ public function test_given_campaigns_are_loaded_then_loaded_campaign_data_is_cor $this->assertEquals( 'B18WPDE_02_180511_top_ctrl_last', $bucketA->getBanner( 10 ) ); } + public function test_loaded_campaign_start_end_dates_are_in_CET_Berlin_timezone(): void { + $loader = new CampaignConfigurationLoader( self::TEST_VALID_CAMPAIGN_CONFIGURATION_FILE ); + $collection = $loader->getCampaignCollection(); + + $campaign = $collection->getCampaign( new DateTime( "2018-11-31 01:23:45" ) ); + + $this->assertNotNull( $campaign ); + $this->assertSame( 'Europe/Berlin', $campaign->getEnd()->getTimezone()->getName() ); + } + public function test_given_broken_bucket_campaign_configuration_then_errors_are_caught(): void { $loader = new CampaignConfigurationLoader( self::TEST_BROKEN_BUCKET_CAMPAIGN_CONFIGURATION_FILE diff --git a/tests/bootstrap.php b/tests/bootstrap.php index f6ad901..77687a0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -5,6 +5,8 @@ require dirname( __DIR__ ) . '/vendor/autoload.php'; +date_default_timezone_set( 'Europe/Berlin' ); + if ( file_exists( dirname( __DIR__ ) . '/config/bootstrap.php' ) ) { require dirname( __DIR__ ) . '/config/bootstrap.php'; } elseif ( method_exists( Dotenv::class, 'bootEnv' ) ) {