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

Revert "use timezone of event"

This reverts commit 9662e1f333.
This commit is contained in:
Daniel Waxweiler
2025-05-26 10:20:11 +02:00
parent 9662e1f333
commit be8fd96ee9
12 changed files with 57 additions and 22 deletions

View File

@@ -1,10 +0,0 @@
<?php
namespace MobilizonConnector;
final class DateTimeFormatter
{
public static function format(\DateTimeImmutable $dateTime, string $format) {
$timestamp = $dateTime->getTimestamp();
return date_i18n($format, $timestamp);
}
}

View File

@@ -53,6 +53,7 @@ class EventsListBlock {
$dateFormat = SiteSettings::getDateFormat();
$timeFormat = SiteSettings::getTimeFormat();
$timeZone = SiteSettings::getTimeZone();
require dirname(__DIR__) . '/view/events-list.php';
} catch (GeneralException $e) {

View File

@@ -36,6 +36,7 @@ class EventsListShortcut {
$dateFormat = SiteSettings::getDateFormat();
$timeFormat = SiteSettings::getTimeFormat();
$timeZone = SiteSettings::getTimeZone();
require dirname(__DIR__) . '/view/events-list.php';
} catch (GeneralException $e) {

View File

@@ -36,6 +36,7 @@ class EventsListWidget extends \WP_Widget {
$dateFormat = SiteSettings::getDateFormat();
$timeFormat = SiteSettings::getTimeFormat();
$timeZone = SiteSettings::getTimeZone();
require dirname(__DIR__) . '/view/events-list.php';
} catch (GeneralException $e) {

View File

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

View File

@@ -0,0 +1,15 @@
<?php
namespace MobilizonConnector;
final class LocalDateTime {
private $dateTime;
public function __construct(string $text, \DateTimeZone $timeZone) {
$date = new \DateTimeImmutable($text);
$this->dateTime = $date->setTimezone($timeZone);
}
public function getValue() {
return $this->dateTime;
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace MobilizonConnector;
final class LocalDateTimeFormatter
{
public static function format(LocalDateTime $dateTime, string $format) {
$timestamp = $dateTime->getValue()->getTimestamp();
return date_i18n($format, $timestamp);
}
}

View File

@@ -14,4 +14,8 @@ class SiteSettings {
return get_option(self::$OPTION_NAME_TIME_FORMAT);
}
public static function getTimeZone() {
return wp_timezone();
}
}