1
0
mirror of https://github.com/dwaxweiler/connector-mobilizon synced 2025-06-05 21:59:25 +02:00

fix offset

This commit is contained in:
Daniel Waxweiler
2023-05-21 16:11:24 +02:00
parent 1866e75f70
commit 063458b2c9
4 changed files with 18 additions and 18 deletions

View File

@ -18,17 +18,17 @@ final class DateTimeWrapper {
$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 {
$formatter = \IntlDateFormatter::create($this->locale, \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE, $this->timeZone);
return $formatter->format($this->dateTime);
}
public function getOffset(): string {
return $this->timeZone->getOffset($this->dateTime);
}
public function get24Time(): string {
$formatter = \IntlDateFormatter::create($this->locale, \IntlDateFormatter::NONE, \IntlDateFormatter::SHORT, $this->timeZone);
return $formatter->format($this->dateTime);
public function getTimeZoneName(): string {
return $this->timeZone->getName();
}
}

View File

@ -8,7 +8,7 @@ final class Formatter
$dateText = $startDateTime->getShortDate();
$dateText .= ' ' . $startDateTime->get24Time();
if (!$end && $isShortOffsetNameShown) {
$dateText .= ' (' . $startDateTime->getOffset() . ')';
$dateText .= ' (' . $startDateTime->getTimeZoneName() . ')';
}
if ($end) {
$endDateTime = new DateTimeWrapper($end, $locale, $timeZone);
@ -20,7 +20,7 @@ final class Formatter
}
$dateText .= $endDateTime->get24Time();
if ($isShortOffsetNameShown) {
$dateText .= ' (' . $endDateTime->getOffset() . ')';
$dateText .= ' (' . $endDateTime->getTimeZoneName() . ')';
}
}
return $dateText;

View File

@ -5,6 +5,11 @@ use MobilizonConnector\DateTimeWrapper;
use PHPUnit\Framework\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 {
$d = new DateTimeWrapper('2020-12-24T16:45:00Z');
$this->assertSame('24/12/2020', $d->getShortDate());
@ -35,13 +40,8 @@ final class DateTimeWrapperTest extends TestCase {
$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 {
$d = new DateTimeWrapper('2020-12-24T16:45:00Z');
$this->assertSame('0', $d->getOffset()); // TODO was UTC
$this->assertSame('UTC', $d->getTimeZoneName());
}
}

View File

@ -11,7 +11,7 @@ final class FormatterTest extends PHPUnit\Framework\TestCase
}
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 {
@ -23,7 +23,7 @@ final class FormatterTest extends PHPUnit\Framework\TestCase
}
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 {
@ -31,7 +31,7 @@ final class FormatterTest extends PHPUnit\Framework\TestCase
}
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 {