Skip to content

Commit

Permalink
Retrieve time in UTC by default unless $localize is set to true. #6296
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyratilal committed Jun 28, 2018
1 parent ab7539d commit 4c77cdc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
30 changes: 9 additions & 21 deletions includes/class-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,23 @@ public function get_date_format_string( $format = 'date' ) {
/**
* Retrieves a date instance for the WP timezone (and offset) based on the given date string.
*
* Incoming time is expected to be UTC.
*
* @since 3.0
*
* @param string $date_string Optional. Date string. Default 'now'.
* @param string $timezone Optional. Timezone to generate the Carbon instance for.
* Default is the timezone set in WordPress settings.
* @param bool $apply_offset Optional. Whether to apply the offset in seconds to the generated
* date. Default true.
* @return \EDD\Utils\Date Date instance.
* @param bool $localize Optional. Whether to apply the offset in seconds to the generated
* date. Default false.
*
* @return \EDD\Utils\Date Date instance. Time is returned as UTC.
*/
public function date( $date_string = 'now', $timezone = null, $apply_offset = true ) {
public function date( $date_string = 'now', $timezone = null, $localize = false ) {

// Fallback to this time zone
if ( null === $timezone ) {
if ( null === $timezone && true === $localize ) {
$timezone = $this->get_time_zone();
} elseif ( null === $timezone && false === $localize ) {
$timezone = 'UTC';
}

/*
Expand All @@ -227,7 +228,7 @@ public function date( $date_string = 'now', $timezone = null, $apply_offset = tr
*/
$date = new Utils\Date( $date_string, new \DateTimezone( $timezone ) );

if ( false === $apply_offset ) {
if ( false === $localize ) {
/*
* The offset is automatically applied when the Date object is instantiated.
*
Expand Down Expand Up @@ -317,19 +318,6 @@ public function get_time_zone( $refresh = false ) {
* @since 3.0
*/
private function set_gmt_offset() {

// We need to calculate the GMT offset and these are a few ways this can be done.

// First, try and fetch a value from wp_options.
$offset = get_option( 'gmt_offset' );

// Get the timezone if gmt_offset does not exist in wp_options.
if ( empty( $offset ) ) {
$timezone = $this->get_time_zone( true );


}

$this->gmt_offset = get_option( 'gmt_offset', 0 ) * HOUR_IN_SECONDS;
}

Expand Down
4 changes: 2 additions & 2 deletions includes/orders/class-stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -2458,8 +2458,8 @@ private static function get_db() {
*/
private function set_date_ranges() {

// Do not apply an offset as we're passing in current server time.
$date = EDD()->utils->date( 'now' );
// Retrieve the UTC time
$date = EDD()->utils->date();

$date_filters = Reports\get_dates_filter_options();

Expand Down

0 comments on commit 4c77cdc

Please sign in to comment.