Skip to content

Commit

Permalink
Ensure DateTimeZone is constructed only when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
delawski committed Jul 15, 2024
1 parent 4decb64 commit b26fa09
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions classes/class-date-interval.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ public function get_predefined_intervals() {
if ( false === $timezone ) {
$timezone = timezone_name_from_abbr( '', $gmt_offset * 3600, false );
}
if ( false === $timezone ) {
$timezone = null;
}
}

try {
$today = new \DateTimeImmutable( 'today', new \DateTimeZone( $timezone ) );
$timezone_object = $timezone ? new \DateTimeZone( $timezone ) : null;
} catch ( \Exception $e ) {
$timezone_object = null;
}

try {
$today = new \DateTimeImmutable( 'today', $timezone_object );
$date_intervals = array(
'today' => array(
'label' => esc_html__( 'Today', 'stream' ),
Expand Down Expand Up @@ -121,7 +124,7 @@ public function get_predefined_intervals() {
}

/**
* Allow other plugins to filter the predefined date intervals
* Allow other plugins to filter the predefined date intervals.
*
* @param array $date_intervals Date intervals array.
* @param string $timezone Timezone.
Expand Down

0 comments on commit b26fa09

Please sign in to comment.