1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-06 11:12:43 +01:00
invoiceninja/tests/Unit/MakesDatesTest.php

91 lines
3.0 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Unit;
2019-04-23 00:41:32 +02:00
use App\Utils\Traits\MakesDates;
use Tests\TestCase;
/**
* @test
2019-04-23 00:41:32 +02:00
* @covers App\Utils\Traits\MakesDates
*/
2019-04-23 00:41:32 +02:00
class MakesDatesTest extends TestCase
{
use MakesDates;
/*
* tests may break with daylight savings changes ( as PHP handle DST under the hood )
* these tests are to confirm the timezone conversions
* work as expected at this point in time.
*/
public function testConvertClientDateToUTCDateTimeTickOverSameDay()
{
$date_src = '2007-04-19 23:59';
$client_timezone = 'Europe/Amsterdam'; // +1 UTC
$date_time = new \DateTime($date_src, new \DateTimeZone($client_timezone));
$utc_date = $this->createUtcDate($date_time, $client_timezone);
2019-04-22 14:17:52 +02:00
$this->assertEquals('2007-04-19 21:59', $date_time->format('Y-m-d H:i'));
}
2019-04-22 14:17:52 +02:00
public function testConvertClientDateToUTCDateTimeSameDay()
{
$date_src = '2007-04-19 21:59';
$client_timezone = 'Europe/Amsterdam'; // +1 UTC
$date_time = new \DateTime($date_src, new \DateTimeZone($client_timezone));
2019-04-22 14:17:52 +02:00
$utc_date = $this->createUtcDate($date_time, $client_timezone);
2019-04-22 14:17:52 +02:00
$this->assertEquals($utc_date->format('Y-m-d'), '2007-04-19');
}
2019-04-22 14:17:52 +02:00
public function testConvertClientDateToUTCDateTimeTickOverNextDay()
{
$date_src = '2007-04-19 23:59';
$client_timezone = 'Atlantic/Cape_Verde'; // -1 UTC
$date_time = new \DateTime($date_src, new \DateTimeZone($client_timezone));
2019-04-22 14:17:52 +02:00
$utc_date = $this->createUtcDate($date_time, $client_timezone);
2019-04-22 14:17:52 +02:00
$this->assertEquals('2007-04-20 00:59', $date_time->format('Y-m-d H:i'));
}
2019-08-28 01:19:54 +02:00
public function testConvertClientDateToUTCDateTimeSameDayDiffTimeZone()
{
$date_src = '2007-04-19 22:59';
$client_timezone = 'Atlantic/Cape_Verde'; // -1 UTC
$date_time = new \DateTime($date_src, new \DateTimeZone($client_timezone));
2019-08-28 01:19:54 +02:00
$utc_date = $this->createUtcDate($date_time, $client_timezone);
2019-08-28 01:19:54 +02:00
$this->assertEquals('2007-04-19 23:59', $date_time->format('Y-m-d H:i'));
}
2019-08-28 01:19:54 +02:00
public function testCreateClientDate()
{
$client_date_src = '2007-04-19 22:59';
$client_timezone = 'Atlantic/Cape_Verde'; // -1 UTC
$date_time = new \DateTime($client_date_src, new \DateTimeZone($client_timezone));
2019-08-28 02:58:13 +02:00
$utc_date = $this->createUtcDate($date_time, $client_timezone);
$client_date = $this->createClientDate($utc_date, $client_timezone);
2019-08-28 02:58:13 +02:00
$this->assertEquals('2007-04-19 22:59', $client_date->format('Y-m-d H:i'));
}
2019-08-28 02:58:13 +02:00
public function testCreateClientDateWithFormat()
{
$client_date_src = '2007-04-19';
$client_timezone = 'Atlantic/Cape_Verde'; // -1 UTC
$date_time = new \DateTime($client_date_src, new \DateTimeZone($client_timezone));
2019-08-28 02:58:13 +02:00
$utc_date = $this->createUtcDate($date_time, $client_timezone);
$client_date = $this->createClientDate($utc_date, $client_timezone);
2019-04-22 14:17:52 +02:00
$this->assertEquals('2007-04-19', $client_date->format('Y-m-d'));
}
}