mirror of
				https://github.com/dwaxweiler/connector-mobilizon
				synced 2025-06-05 21:59:25 +02:00 
			
		
		
		
	fix empty WordPress timezone_string option resulting in Invalid DateTime [#10]
This commit is contained in:
		@@ -5,6 +5,7 @@
 | 
			
		||||
#### Deprecated
 | 
			
		||||
#### Removed
 | 
			
		||||
#### Fixed
 | 
			
		||||
- Fix empty WordPress timezone_string option resulting in Invalid DateTime
 | 
			
		||||
#### Security
 | 
			
		||||
 | 
			
		||||
### [0.6.1] - 2021-07-13
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,26 @@ test('#getShortDate usual date', t => {
 | 
			
		||||
  t.is(d.getShortDate(), '24/12/2020')
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
test('#getShortDate usual date with timezone string', t => {
 | 
			
		||||
  const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z', timeZone: 'Europe/Rome' })
 | 
			
		||||
  t.is(d.getShortDate(), '24/12/2020')
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
test('#getShortDate usual date with fixed offset', t => {
 | 
			
		||||
  const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z', timeZone: 'UTC+02:00' })
 | 
			
		||||
  t.is(d.getShortDate(), '24/12/2020')
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
test('#getShortDate usual date with fixed offset without UTC prefix', t => {
 | 
			
		||||
  const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z', timeZone: '+02:00' })
 | 
			
		||||
  t.is(d.getShortDate(), '24/12/2020')
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
test('#getShortDate usual date with empty time zone', t => {
 | 
			
		||||
  const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z', timeZone: '' })
 | 
			
		||||
  t.is(d.getShortDate(), '24/12/2020')
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
test('#get24Time usual time', t => {
 | 
			
		||||
  const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
 | 
			
		||||
  t.is(d.get24Time(), '16:45')
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,12 @@ import { DateTime } from 'luxon'
 | 
			
		||||
export default class DateTimeWrapper {
 | 
			
		||||
 | 
			
		||||
  constructor({ locale = 'en-GB', text, timeZone = 'utc' } = {}) {
 | 
			
		||||
    if (!timeZone) {
 | 
			
		||||
      timeZone = 'utc'
 | 
			
		||||
    }
 | 
			
		||||
    if (timeZone.includes(':') && timeZone.substring(0, 3).toUpperCase() !== 'UTC') {
 | 
			
		||||
      timeZone = 'UTC' + timeZone
 | 
			
		||||
    }
 | 
			
		||||
    this.dateTime = DateTime.fromISO(text, { locale, zone: timeZone })
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -29,7 +29,7 @@ class EventsListShortcut {
 | 
			
		||||
    $locale = str_replace('_', '-', get_locale());
 | 
			
		||||
    $groupName = $atts_with_overriden_defaults['group-name'];
 | 
			
		||||
    $url = Settings::getUrl();
 | 
			
		||||
    $timeZone = get_option('timezone_string');
 | 
			
		||||
    $timeZone = wp_timezone_string();
 | 
			
		||||
    $isShortOffsetNameShown = Settings::isShortOffsetNameShown();
 | 
			
		||||
 | 
			
		||||
    ob_start();
 | 
			
		||||
 
 | 
			
		||||
@@ -30,7 +30,7 @@ class EventsListWidget extends \WP_Widget {
 | 
			
		||||
    $locale = str_replace('_', '-', get_locale());
 | 
			
		||||
    $groupName = isset($options['groupName']) ? $options['groupName'] : '';
 | 
			
		||||
    $url = Settings::getUrl();
 | 
			
		||||
    $timeZone = get_option('timezone_string');
 | 
			
		||||
    $timeZone = wp_timezone_string();
 | 
			
		||||
    $isShortOffsetNameShown = Settings::isShortOffsetNameShown();
 | 
			
		||||
 | 
			
		||||
    require dirname(__DIR__) . '/view/events-list.php';
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user