public function testTransformDifferentTimezones() { $transformer = new DateTimeToArrayTransformer('America/New_York', 'Asia/Hong_Kong'); $input = new \DateTime('2010-02-03 04:05:06 America/New_York'); $dateTime = new \DateTime('2010-02-03 04:05:06 America/New_York'); $dateTime->setTimezone(new \DateTimeZone('Asia/Hong_Kong')); $output = array('year' => (string) (int) $dateTime->format('Y'), 'month' => (string) (int) $dateTime->format('m'), 'day' => (string) (int) $dateTime->format('d'), 'hour' => (string) (int) $dateTime->format('H'), 'minute' => (string) (int) $dateTime->format('i'), 'second' => (string) (int) $dateTime->format('s')); $this->assertSame($output, $transformer->transform($input)); }
public function testTransformDateTimeImmutable() { if (PHP_VERSION_ID < 50500) { $this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0'); } $transformer = new DateTimeToArrayTransformer('America/New_York', 'Asia/Hong_Kong'); $input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York'); $dateTime = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York'); $dateTime = $dateTime->setTimezone(new \DateTimeZone('Asia/Hong_Kong')); $output = array('year' => (string) (int) $dateTime->format('Y'), 'month' => (string) (int) $dateTime->format('m'), 'day' => (string) (int) $dateTime->format('d'), 'hour' => (string) (int) $dateTime->format('H'), 'minute' => (string) (int) $dateTime->format('i'), 'second' => (string) (int) $dateTime->format('s')); $this->assertSame($output, $transformer->transform($input)); }