mirror of
https://github.com/dwaxweiler/connector-mobilizon
synced 2025-06-05 21:59:25 +02:00
fix offset
This commit is contained in:
@ -18,17 +18,17 @@ final class DateTimeWrapper {
|
|||||||
$this->timeZone = new \DateTimeZone($timeZone);
|
$this->timeZone = new \DateTimeZone($timeZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get24Time(): string {
|
||||||
|
$formatter = \IntlDateFormatter::create($this->locale, \IntlDateFormatter::NONE, \IntlDateFormatter::SHORT, $this->timeZone);
|
||||||
|
return $formatter->format($this->dateTime);
|
||||||
|
}
|
||||||
|
|
||||||
public function getShortDate(): string {
|
public function getShortDate(): string {
|
||||||
$formatter = \IntlDateFormatter::create($this->locale, \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE, $this->timeZone);
|
$formatter = \IntlDateFormatter::create($this->locale, \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE, $this->timeZone);
|
||||||
return $formatter->format($this->dateTime);
|
return $formatter->format($this->dateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOffset(): string {
|
public function getTimeZoneName(): string {
|
||||||
return $this->timeZone->getOffset($this->dateTime);
|
return $this->timeZone->getName();
|
||||||
}
|
|
||||||
|
|
||||||
public function get24Time(): string {
|
|
||||||
$formatter = \IntlDateFormatter::create($this->locale, \IntlDateFormatter::NONE, \IntlDateFormatter::SHORT, $this->timeZone);
|
|
||||||
return $formatter->format($this->dateTime);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ final class Formatter
|
|||||||
$dateText = $startDateTime->getShortDate();
|
$dateText = $startDateTime->getShortDate();
|
||||||
$dateText .= ' ' . $startDateTime->get24Time();
|
$dateText .= ' ' . $startDateTime->get24Time();
|
||||||
if (!$end && $isShortOffsetNameShown) {
|
if (!$end && $isShortOffsetNameShown) {
|
||||||
$dateText .= ' (' . $startDateTime->getOffset() . ')';
|
$dateText .= ' (' . $startDateTime->getTimeZoneName() . ')';
|
||||||
}
|
}
|
||||||
if ($end) {
|
if ($end) {
|
||||||
$endDateTime = new DateTimeWrapper($end, $locale, $timeZone);
|
$endDateTime = new DateTimeWrapper($end, $locale, $timeZone);
|
||||||
@ -20,7 +20,7 @@ final class Formatter
|
|||||||
}
|
}
|
||||||
$dateText .= $endDateTime->get24Time();
|
$dateText .= $endDateTime->get24Time();
|
||||||
if ($isShortOffsetNameShown) {
|
if ($isShortOffsetNameShown) {
|
||||||
$dateText .= ' (' . $endDateTime->getOffset() . ')';
|
$dateText .= ' (' . $endDateTime->getTimeZoneName() . ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $dateText;
|
return $dateText;
|
||||||
|
@ -5,6 +5,11 @@ use MobilizonConnector\DateTimeWrapper;
|
|||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class DateTimeWrapperTest extends TestCase {
|
final class DateTimeWrapperTest extends TestCase {
|
||||||
|
public function testCanGet24TimeForUsualTime(): void {
|
||||||
|
$d = new DateTimeWrapper('2020-12-24T16:45:00Z');
|
||||||
|
$this->assertSame('16:45', $d->get24Time());
|
||||||
|
}
|
||||||
|
|
||||||
public function testCanGetShortDateForUsualDate(): void {
|
public function testCanGetShortDateForUsualDate(): void {
|
||||||
$d = new DateTimeWrapper('2020-12-24T16:45:00Z');
|
$d = new DateTimeWrapper('2020-12-24T16:45:00Z');
|
||||||
$this->assertSame('24/12/2020', $d->getShortDate());
|
$this->assertSame('24/12/2020', $d->getShortDate());
|
||||||
@ -35,13 +40,8 @@ final class DateTimeWrapperTest extends TestCase {
|
|||||||
$this->assertSame('24/12/2020', $d->getShortDate());
|
$this->assertSame('24/12/2020', $d->getShortDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanGet24TimeForUsualTime(): void {
|
|
||||||
$d = new DateTimeWrapper('2020-12-24T16:45:00Z');
|
|
||||||
$this->assertSame('16:45', $d->get24Time());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCanGetShortOffsetNameForUsualTime(): void {
|
public function testCanGetShortOffsetNameForUsualTime(): void {
|
||||||
$d = new DateTimeWrapper('2020-12-24T16:45:00Z');
|
$d = new DateTimeWrapper('2020-12-24T16:45:00Z');
|
||||||
$this->assertSame('0', $d->getOffset()); // TODO was UTC
|
$this->assertSame('UTC', $d->getTimeZoneName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ final class FormatterTest extends PHPUnit\Framework\TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testCanDateFormatOneDateWithOffset(): void {
|
public function testCanDateFormatOneDateWithOffset(): void {
|
||||||
$this->assertSame('15/04/2021 10:30 - 15:30 (0)', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', '2021-04-15T15:30:00Z', true));
|
$this->assertSame('15/04/2021 10:30 - 15:30 (UTC)', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', '2021-04-15T15:30:00Z', true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanDateFormatOneDateWithTimeZoneOffset(): void {
|
public function testCanDateFormatOneDateWithTimeZoneOffset(): void {
|
||||||
@ -23,7 +23,7 @@ final class FormatterTest extends PHPUnit\Framework\TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testCanDateFormatTwoDatesWithOffset(): void {
|
public function testCanDateFormatTwoDatesWithOffset(): void {
|
||||||
$this->assertSame('15/04/2021 10:30 - 16/04/2021 15:30 (0)', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', '2021-04-16T15:30:00Z', true));
|
$this->assertSame('15/04/2021 10:30 - 16/04/2021 15:30 (UTC)', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', '2021-04-16T15:30:00Z', true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanDateFormatWhenSecondDateIsNull(): void {
|
public function testCanDateFormatWhenSecondDateIsNull(): void {
|
||||||
@ -31,7 +31,7 @@ final class FormatterTest extends PHPUnit\Framework\TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testCanDateFormatWhenSecondDateIsNullWithOffset(): void {
|
public function testCanDateFormatWhenSecondDateIsNullWithOffset(): void {
|
||||||
$this->assertSame('15/04/2021 10:30 (0)', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', null, true));
|
$this->assertSame('15/04/2021 10:30 (UTC)', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', null, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanLocationFormatBothParameters(): void {
|
public function testCanLocationFormatBothParameters(): void {
|
||||||
|
Reference in New Issue
Block a user