1
0
mirror of https://github.com/dwaxweiler/connector-mobilizon synced 2025-06-05 21:59:25 +02:00
Files
connector-wordpress/source/includes/LineFormatter.php
Daniel Waxweiler be8fd96ee9 Revert "use timezone of event"
This reverts commit 9662e1f333.
2025-05-26 10:20:11 +02:00

42 lines
1.2 KiB
PHP

<?php
namespace MobilizonConnector;
final class LineFormatter
{
public static function format_date_time(\DateTimeZone $timeZone, string $dateFormat, string $timeFormat, string $start, ?string $end): string {
$startDateTime = new LocalDateTime($start, $timeZone);
$startDate = LocalDateTimeFormatter::format($startDateTime, $dateFormat);
$startTime = LocalDateTimeFormatter::format($startDateTime, $timeFormat);
$dateText = $startDate . ' ' . $startTime;
if ($end) {
$endDateTime = new LocalDateTime($end, $timeZone);
$endDate = LocalDateTimeFormatter::format($endDateTime, $dateFormat);
$endTime = LocalDateTimeFormatter::format($endDateTime, $timeFormat);
if ($startDate != $endDate) {
$dateText .= ' - ';
$dateText .= $endDate . ' ';
} else {
$dateText .= ' - ';
}
$dateText .= $endTime;
}
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;
}
}