Skip to content

Commit 7bef7c2

Browse files
committed
issue #2 add small test for timezones
1 parent ccf4bbf commit 7bef7c2

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

Diff for: tests/SapDateTimeTest.php

+49
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,53 @@ public function testCreateSapTimestamps($isotime, $saptime)
258258
$dateTime = new SapDateTime($isotime);
259259
static::assertSame($saptime, $dateTime->format(SapDateTime::SAP_TIMESTAMP));
260260
}
261+
262+
/**
263+
* Data provider for timezones.
264+
* @return array
265+
*/
266+
public static function provideTimezones()
267+
{
268+
return [
269+
[
270+
SapDateTime::SAP_TIMESTAMP,
271+
'20200301000102',
272+
new \DateTimeZone('CET'),
273+
'2020-03-01T00:01:02+01:00',
274+
'2020-02-29T23:01:02+00:00'
275+
],
276+
[
277+
'Y-m-d H:i:s',
278+
'2020-03-01 00:01:02',
279+
new \DateTimeZone('CET'),
280+
'2020-03-01T00:01:02+01:00',
281+
'2020-02-29T23:01:02+00:00'
282+
],
283+
[
284+
SapDateTime::SAP_DATE,
285+
'20200301',
286+
new \DateTimeZone('CET'),
287+
'2020-03-01T00:00:00+01:00',
288+
'2020-02-29T23:00:00+00:00'
289+
]
290+
];
291+
}
292+
293+
/**
294+
* Test timezones.
295+
* @dataProvider provideTimezones
296+
* @param string $format
297+
* @param string $time
298+
* @param \DateTimeZone $zone
299+
* @param string $expected
300+
* @param string $utc
301+
* @throws \Exception
302+
*/
303+
public function testTimezones($format, $time, $zone, $expected, $utc)
304+
{
305+
$dateTime = SapDateTime::createFromFormat($format, $time, $zone);
306+
static::assertSame($expected, $dateTime->format('c'));
307+
$dateTime->setTimezone(new \DateTimeZone('UTC'));
308+
static::assertSame($utc, $dateTime->format('c'));
309+
}
261310
}

0 commit comments

Comments
 (0)