| @@ -3,8 +3,13 @@ | ||
| 3 | 3 | * WPCOM_JSON_API_Date class. |
| 4 | 4 | * |
| 5 | 5 | * @package automattic/jetpack |
| 6 | 6 | */ |
| 7 | + | |
| 8 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 9 | + exit( 0 ); | |
| 10 | +} | |
| 11 | + | |
| 7 | 12 | /** |
| 8 | 13 | * Base class for WPCOM_JSON_API_Date. |
| 9 | 14 | */ |
| 10 | 15 | class WPCOM_JSON_API_Date { |
| @@ -16,9 +21,9 @@ | ||
| 16 | 21 | * |
| 17 | 22 | * @return string |
| 18 | 23 | */ |
| 19 | 24 | public static function format_date( $date_gmt, $date = null ) { |
| 20 | - $offset = null; | |
| 25 | + $offset = 0; | |
| 21 | 26 | $timestamp_gmt = strtotime( "$date_gmt+0000" ); |
| 22 | 27 | |
| 23 | 28 | if ( null === $date ) { |
| 24 | 29 | $timestamp = $timestamp_gmt; |
| @@ -46,9 +51,9 @@ | ||
| 46 | 51 | if ( $timezone ) { |
| 47 | 52 | $offset = $timezone->getOffset( $date_time ); |
| 48 | 53 | } |
| 49 | 54 | } else { |
| 50 | - $offset = 3600 * get_option( 'gmt_offset' ); | |
| 55 | + $offset = 3600 * (float) get_option( 'gmt_offset' ); | |
| 51 | 56 | } |
| 52 | 57 | } else { |
| 53 | 58 | $offset = $timestamp - $timestamp_gmt; |
| 54 | 59 | } |
| @@ -59,9 +64,9 @@ | ||
| 59 | 64 | $offset -= $hours * 3600; |
| 60 | 65 | $minutes = (int) floor( $offset / 60 ); |
| 61 | 66 | } |
| 62 | 67 | |
| 63 | - return (string) gmdate( 'Y-m-d\\TH:i:s', $timestamp ) . sprintf( '%s%02d:%02d', $west ? '-' : '+', $hours, $minutes ); | |
| 68 | + return gmdate( 'Y-m-d\\TH:i:s', $timestamp ) . sprintf( '%s%02d:%02d', $west ? '-' : '+', $hours, $minutes ); | |
| 64 | 69 | } |
| 65 | 70 | |
| 66 | 71 | /** |
| 67 | 72 | * Returns ISO 8601 formatted duration interval: P0DT1H10M0S |
| @@ -77,18 +82,18 @@ | ||
| 77 | 82 | if ( empty( $timestamp ) ) { |
| 78 | 83 | return; |
| 79 | 84 | } |
| 80 | 85 | |
| 81 | - $days = floor( $timestamp / 86400 ); | |
| 82 | - $timestamp = $timestamp % 86400; | |
| 86 | + $days = floor( $timestamp / 86400 ); | |
| 87 | + $timestamp %= 86400; | |
| 83 | 88 | |
| 84 | - $hours = floor( $timestamp / 3600 ); | |
| 85 | - $timestamp = $timestamp % 3600; | |
| 89 | + $hours = floor( $timestamp / 3600 ); | |
| 90 | + $timestamp %= 3600; | |
| 86 | 91 | |
| 87 | - $minutes = floor( $timestamp / 60 ); | |
| 88 | - $timestamp = $timestamp % 60; | |
| 92 | + $minutes = floor( $timestamp / 60 ); | |
| 93 | + $timestamp %= 60; | |
| 89 | 94 | |
| 90 | - return (string) sprintf( | |
| 95 | + return sprintf( | |
| 91 | 96 | 'P%dDT%dH%dM%dS', |
| 92 | 97 | $days, |
| 93 | 98 | $hours, |
| 94 | 99 | $minutes, |