summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/sal/class.json-api-date.php')
-rw-r--r--plugins/jetpack/sal/class.json-api-date.php39
1 files changed, 24 insertions, 15 deletions
diff --git a/plugins/jetpack/sal/class.json-api-date.php b/plugins/jetpack/sal/class.json-api-date.php
index c5c0cb38..106187a0 100644
--- a/plugins/jetpack/sal/class.json-api-date.php
+++ b/plugins/jetpack/sal/class.json-api-date.php
@@ -1,20 +1,29 @@
-<?php
-
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * WPCOM_JSON_API_Date class.
+ *
+ * @package automattic/jetpack
+ */
+/**
+ * Base class for WPCOM_JSON_API_Date.
+ */
class WPCOM_JSON_API_Date {
/**
* Returns ISO 8601 formatted datetime: 2011-12-08T01:15:36-08:00
*
- * @param $date_gmt (string) GMT datetime string.
- * @param $date (string) Optional. Used to calculate the offset from GMT.
+ * @param string $date_gmt GMT datetime string.
+ * @param string $date Optional. Used to calculate the offset from GMT.
*
* @return string
*/
- static function format_date( $date_gmt, $date = null ) {
+ public static function format_date( $date_gmt, $date = null ) {
$timestamp_gmt = strtotime( "$date_gmt+0000" );
if ( null === $date ) {
$timestamp = $timestamp_gmt;
- $hours = $minutes = $west = 0;
+ $west = 0;
+ $minutes = 0;
+ $hours = 0;
} else {
$date_time = date_create( "$date+0000" );
if ( $date_time ) {
@@ -24,9 +33,9 @@ class WPCOM_JSON_API_Date {
}
// "0000-00-00 00:00:00" == -62169984000
- if ( - 62169984000 == $timestamp_gmt ) {
+ if ( -62169984000 === $timestamp_gmt ) {
// WordPress sets post_date=now, post_date_gmt="0000-00-00 00:00:00" for all drafts
- // WordPress sets post_modified=now, post_modified_gmt="0000-00-00 00:00:00" for new drafts
+ // WordPress sets post_modified=now, post_modified_gmt="0000-00-00 00:00:00" for new drafts.
// Try to guess the correct offset from the blog's options.
$timezone_string = get_option( 'timezone_string' );
@@ -43,9 +52,9 @@ class WPCOM_JSON_API_Date {
$offset = $timestamp - $timestamp_gmt;
}
- $west = $offset < 0;
- $offset = abs( $offset );
- $hours = (int) floor( $offset / 3600 );
+ $west = $offset < 0;
+ $offset = abs( $offset );
+ $hours = (int) floor( $offset / 3600 );
$offset -= $hours * 3600;
$minutes = (int) floor( $offset / 60 );
}
@@ -60,7 +69,7 @@ class WPCOM_JSON_API_Date {
*
* @return null|string
*/
- static function format_duration( $time ) {
+ public static function format_duration( $time ) {
$timestamp = strtotime( $time, 0 );
// Bail early if we don't recognize a date.
@@ -68,13 +77,13 @@ class WPCOM_JSON_API_Date {
return;
}
- $days = floor( $timestamp / 86400 );
+ $days = floor( $timestamp / 86400 );
$timestamp = $timestamp % 86400;
- $hours = floor( $timestamp / 3600 );
+ $hours = floor( $timestamp / 3600 );
$timestamp = $timestamp % 3600;
- $minutes = floor( $timestamp / 60 );
+ $minutes = floor( $timestamp / 60 );
$timestamp = $timestamp % 60;
return (string) sprintf(