Skip to content

Commit

Permalink
issue #2 add small test for timezones
Browse files Browse the repository at this point in the history
  • Loading branch information
gregor-j committed Feb 28, 2020
1 parent b0f765f commit 23e4ff2
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/SapDateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,53 @@ public function testCreateSapTimestamps($isotime, $saptime)
$dateTime = new SapDateTime($isotime);
static::assertSame($saptime, $dateTime->format(SapDateTime::SAP_TIMESTAMP));
}

/**
* Data provider for timezones.
* @return array
*/
public static function provideTimezones()
{
return [
[
SapDateTime::SAP_TIMESTAMP,
'20200301000102',
new \DateTimeZone('CET'),
'2020-03-01T00:01:02+01:00',
'2020-02-29T23:01:02+00:00'
],
[
'Y-m-d H:i:s',
'2020-03-01 00:01:02',
new \DateTimeZone('CET'),
'2020-03-01T00:01:02+01:00',
'2020-02-29T23:01:02+00:00'
],
[
SapDateTime::SAP_DATE,
'20200301',
new \DateTimeZone('CET'),
'2020-03-01T00:00:00+01:00',
'2020-02-29T23:00:00+00:00'
]
];
}

/**
* Test timezones.
* @dataProvider provideTimezones
* @param string $format
* @param string $time
* @param \DateTimeZone $zone
* @param string $expected
* @param string $utc
* @throws \Exception
*/
public function testTimezones($format, $time, $zone, $expected, $utc)
{
$dateTime = SapDateTime::createFromFormat($format, $time, $zone);
static::assertSame($expected, $dateTime->format('c'));
$dateTime->setTimezone(new \DateTimeZone('UTC'));
static::assertSame($utc, $dateTime->format('c'));
}
}

0 comments on commit 23e4ff2

Please # to comment.