Skip to content

Commit ed3d218

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

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ 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+
$systemTimezone = date_default_timezone_get();
54+
date_default_timezone_set( 'UTC' );
55+
56+
$campaign = $collection->getCampaign( new DateTime( "2018-11-31 01:23:45", new \DateTimeZone( 'Europe/Berlin' ) ) );
57+
58+
$this->assertNotNull( $campaign );
59+
$this->assertSame( 'Europe/Berlin', $campaign->getEnd()->getTimezone()->getName() );
60+
61+
// restore system time zone
62+
date_default_timezone_set( $systemTimezone );
63+
}
64+
5065
public function test_given_broken_bucket_campaign_configuration_then_errors_are_caught(): void {
5166
$loader = new CampaignConfigurationLoader(
5267
self::TEST_BROKEN_BUCKET_CAMPAIGN_CONFIGURATION_FILE

0 commit comments

Comments
 (0)