connector-wordpress/source/includes/Formatter.php

43 lines
1.3 KiB
PHP
Raw Normal View History

2022-05-19 07:50:18 +02:00
<?php
2023-05-07 22:19:47 +02:00
namespace MobilizonConnector;
2022-05-19 07:50:18 +02:00
final class Formatter
{
public static function format_date(string $locale, string $timeZone, string $start, ?string $end, bool $isShortOffsetNameShown): string {
$startDateTime = new DateTimeWrapper($start, $locale, $timeZone);
$dateText = $startDateTime->getShortDate();
$dateText .= ' ' . $startDateTime->get24Time();
if (!$end && $isShortOffsetNameShown) {
2023-05-21 16:11:24 +02:00
$dateText .= ' (' . $startDateTime->getTimeZoneName() . ')';
2022-05-19 07:50:18 +02:00
}
if ($end) {
$endDateTime = new DateTimeWrapper($end, $locale, $timeZone);
if ($startDateTime->getShortDate() != $endDateTime->getShortDate()) {
$dateText .= ' - ';
$dateText .= $endDateTime->getShortDate() . ' ';
} else {
$dateText .= ' - ';
}
$dateText .= $endDateTime->get24Time();
if ($isShortOffsetNameShown) {
2023-05-21 16:11:24 +02:00
$dateText .= ' (' . $endDateTime->getTimeZoneName() . ')';
2022-05-19 07:50:18 +02:00
}
}
return $dateText;
}
public static function format_location(string $description, string $locality): string {
$location = '';
if ($description && trim($description)) {
$location .= trim($description);
}
if ($location && $locality) {
$location .= ', ';
}
if ($locality) {
$location .= $locality;
}
return $location;
}
}