1
0
mirror of https://github.com/dwaxweiler/connector-mobilizon synced 2025-02-16 11:41:24 +01:00

take WordPress time zone into account

This commit is contained in:
Daniel Waxweiler 2021-05-05 10:40:46 +02:00
parent 22c0b22b8e
commit 89145fe9ed
7 changed files with 15 additions and 8 deletions

View File

@ -1,6 +1,6 @@
### [Unreleased] ### [Unreleased]
#### Added #### Added
- Localise dates based on the WordPress locale - Localise dates based on the WordPress locale and time zone
#### Changed #### Changed
- Clearly list features in `readme.txt` description - Clearly list features in `readme.txt` description
#### Deprecated #### Deprecated

View File

@ -2,8 +2,11 @@ import { DateTime } from 'luxon'
export default class DateTimeWrapper { export default class DateTimeWrapper {
constructor({ locale, text }) { constructor({ locale, text, timeZone }) {
this.dateTime = DateTime.fromISO(text, { locale, setZone: true }) if (!timeZone) {
timeZone = 'utc'
}
this.dateTime = DateTime.fromISO(text, { locale, zone: timeZone })
} }
getShortDate() { getShortDate() {

View File

@ -4,6 +4,7 @@ import { createAnchorElement } from './html-creator'
export function displayEvents({ data, document, list }) { export function displayEvents({ data, document, list }) {
const locale = list.getAttribute('data-locale') const locale = list.getAttribute('data-locale')
const maxEventsCount = list.getAttribute('data-maximum') const maxEventsCount = list.getAttribute('data-maximum')
const timeZone = list.getAttribute('data-time-zone')
const events = data.events ? data.events.elements : data.group.organizedEvents.elements const events = data.events ? data.events.elements : data.group.organizedEvents.elements
const eventsCount = Math.min(maxEventsCount, events.length) const eventsCount = Math.min(maxEventsCount, events.length)
for (let i = 0; i < eventsCount; i++) { for (let i = 0; i < eventsCount; i++) {
@ -15,7 +16,7 @@ export function displayEvents({ data, document, list }) {
const br = document.createElement('br') const br = document.createElement('br')
li.appendChild(br) li.appendChild(br)
const date = Formatter.formatDate({ locale, start: events[i].beginsOn, end: events[i].endsOn }) const date = Formatter.formatDate({ locale, start: events[i].beginsOn, end: events[i].endsOn, timeZone })
const textnode = document.createTextNode(date) const textnode = document.createTextNode(date)
li.appendChild(textnode) li.appendChild(textnode)

View File

@ -2,9 +2,9 @@ import DateTimeWrapper from './date-time-wrapper'
export default class Formatter { export default class Formatter {
static formatDate({ locale, start, end }) { static formatDate({ locale, timeZone, start, end }) {
const startDateTime = new DateTimeWrapper({ locale, text: start }) const startDateTime = new DateTimeWrapper({ locale, text: start, timeZone })
const endDateTime = new DateTimeWrapper({ locale, text: end }) const endDateTime = new DateTimeWrapper({ locale, text: end, timeZone })
let dateText = startDateTime.getShortDate() let dateText = startDateTime.getShortDate()
dateText += ' ' + startDateTime.get24Time() dateText += ' ' + startDateTime.get24Time()
dateText += ' - ' dateText += ' - '

View File

@ -30,6 +30,7 @@ class EventsListShortcut {
$groupName = $atts_with_overriden_defaults['group-name']; $groupName = $atts_with_overriden_defaults['group-name'];
$url = Settings::getUrl(); $url = Settings::getUrl();
$textDomain = TEXT_DOMAIN; $textDomain = TEXT_DOMAIN;
$timeZone = get_option('timezone_string');
ob_start(); ob_start();
require dirname(__DIR__) . '/view/events-list.php'; require dirname(__DIR__) . '/view/events-list.php';

View File

@ -31,6 +31,7 @@ class EventsListWidget extends \WP_Widget {
$groupName = isset($options['groupName']) ? $options['groupName'] : ''; $groupName = isset($options['groupName']) ? $options['groupName'] : '';
$url = Settings::getUrl(); $url = Settings::getUrl();
$textDomain = TEXT_DOMAIN; $textDomain = TEXT_DOMAIN;
$timeZone = get_option('timezone_string');
require dirname(__DIR__) . '/view/events-list.php'; require dirname(__DIR__) . '/view/events-list.php';

View File

@ -8,6 +8,7 @@ if (!defined('ABSPATH')) {
data-url="<?php echo esc_attr($url); ?>" data-url="<?php echo esc_attr($url); ?>"
data-locale="<?php echo esc_attr($locale); ?>" data-locale="<?php echo esc_attr($locale); ?>"
data-maximum="<?php echo esc_attr($eventsCount); ?>" data-maximum="<?php echo esc_attr($eventsCount); ?>"
data-group-name="<?php echo esc_attr($groupName); ?>"> data-group-name="<?php echo esc_attr($groupName); ?>"
data-time-zone="<?php echo esc_attr($timeZone); ?>">
<li style="display: none;"><?php echo esc_html_e('The events could not be loaded!', $textDomain); ?></li> <li style="display: none;"><?php echo esc_html_e('The events could not be loaded!', $textDomain); ?></li>
</ul> </ul>