Skip to content

Commit

Permalink
PHPCS updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kraftbj committed Sep 24, 2019
1 parent 50c4abe commit b6890f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions class.json-api-endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -1533,36 +1533,39 @@ function format_date( $date_gmt, $date = null ) {
* relative to now and will convert it to local time using either the
* timezone set in the options table for the blog or the GMT offset.
*
* @param datetime string
* @param datetime string $date_string Date to parse.
*
* @return array( $local_time_string, $gmt_time_string )
*/
function parse_date( $date_string ) {
public function parse_date( $date_string ) {
$date_string_info = date_parse( $date_string );
if ( is_array( $date_string_info ) && 0 === $date_string_info['error_count'] ) {
// Check if it's already localized. Can't just check is_localtime because date_parse('oppossum') returns true; WTF, PHP.
if ( isset( $date_string_info['zone'] ) && true === $date_string_info['is_localtime'] ) {
$dt_local = clone $dt_utc = new DateTime( $date_string );
$dt_utc = new DateTime( $date_string );
$dt_local = $dt_utc;
$dt_utc->setTimezone( new DateTimeZone( 'UTC' ) );
return array(
(string) $dt_local->format( 'Y-m-d H:i:s' ),
(string) $dt_utc->format( 'Y-m-d H:i:s' ),
);
}

// It's parseable but no TZ info so assume UTC
$dt_local = clone $dt_utc = new DateTime( $date_string, new DateTimeZone( 'UTC' ) );
// It's parseable but no TZ info so assume UTC.
$dt_utc = new DateTime( $date_string, new DateTimeZone( 'UTC' ) );
$dt_local = new DateTime( $date_string, new DateTimeZone( 'UTC' ) );
} else {
// Could not parse time, use now in UTC
$dt_local = clone $dt_utc = new DateTime( 'now', new DateTimeZone( 'UTC' ) );
// Could not parse time, use now in UTC.
$dt_utc = new DateTime( 'now', new DateTimeZone( 'UTC' ) );
$dt_local = $dt_utc;
}

$dt_local->setTimezone( wp_timezone() );

return array(
(string) $dt_local->format( 'Y-m-d H:i:s' ),
(string) $dt_utc->format( 'Y-m-d H:i:s' ),
);
);
}

// Load the functions.php file for the current theme to get its post formats, CPTs, etc.
Expand Down
2 changes: 1 addition & 1 deletion functions.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
exit;
}

if ( ! function_exists( wp_timezone ) ) {
if ( ! function_exists( 'wp_timezone' ) ) {
/**
* Shim for WordPress 5.3's wp_timezone() function.
*
Expand Down

0 comments on commit b6890f1

Please sign in to comment.