Skip to content

Commit f13b865

Browse files
committed
Specify CEST Berlin timezone when parsing start and end dates of campaign
1 parent 8e35a07 commit f13b865

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

public/index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
require __DIR__ . '/../vendor/autoload.php';
99

10+
date_default_timezone_set( 'Europe/Berlin' );
11+
1012
// The check is to ensure we don't use .env in production
1113
if ( !isset( $_SERVER['APP_ENV'] ) && !isset( $_ENV['APP_ENV'] ) ) {
1214
if ( !class_exists( Dotenv::class ) ) {

src/Utils/CampaignConfigurationLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ private function buildCampaignFromData( string $campaignName, array $campaignDat
9595

9696
return new Campaign(
9797
$campaignName,
98-
new \DateTime( $start ),
99-
new \DateTime( $end ),
98+
new \DateTime( $start, new \DateTimeZone( 'Europe/Berlin' ) ),
99+
new \DateTime( $end, new \DateTimeZone( 'Europe/Berlin' ) ),
100100
$trafficLimit,
101101
$category,
102102
new SystemRandomIntegerGenerator(),

tests/Unit/Utils/CampaignConfigurationLoaderTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ public function test_given_campaigns_are_loaded_then_loaded_campaign_data_is_cor
4747
$this->assertEquals( 'B18WPDE_02_180511_top_ctrl_last', $bucketA->getBanner( 10 ) );
4848
}
4949

50+
public function test_loaded_campaign_start_end_dates_are_in_CET_Berlin_timezone(): void {
51+
$loader = new CampaignConfigurationLoader( self::TEST_VALID_CAMPAIGN_CONFIGURATION_FILE );
52+
$collection = $loader->getCampaignCollection();
53+
54+
$campaign = $collection->getCampaign( new DateTime( "2018-11-31 01:23:45" ) );
55+
56+
$this->assertNotNull( $campaign );
57+
$this->assertSame( 'Europe/Berlin', $campaign->getEnd()->getTimezone()->getName() );
58+
}
59+
5060
public function test_given_broken_bucket_campaign_configuration_then_errors_are_caught(): void {
5161
$loader = new CampaignConfigurationLoader(
5262
self::TEST_BROKEN_BUCKET_CAMPAIGN_CONFIGURATION_FILE

tests/bootstrap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
require dirname( __DIR__ ) . '/vendor/autoload.php';
77

8+
date_default_timezone_set( 'Europe/Berlin' );
9+
810
if ( file_exists( dirname( __DIR__ ) . '/config/bootstrap.php' ) ) {
911
require dirname( __DIR__ ) . '/config/bootstrap.php';
1012
} elseif ( method_exists( Dotenv::class, 'bootEnv' ) ) {

0 commit comments

Comments
 (0)