Make WordPress Core

Opened 7 years ago

Closed 6 years ago

#42451 closed defect (bug) (worksforme)

Fix WordPress UTC Time not correct issue

Reported by: taojing10's profile taojing10 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.8.3
Component: Date/Time Keywords: reporter-feedback
Focuses: Cc:

Description (last modified by dd32)

in wp-includes/functions.php, look for

case 'timestamp':
	return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );

change to

case 'timestamp':
	//return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
	return ( $gmt ) ? strtotime(gmdate('Y-m-d H:i:s')) : strtotime(gmdate('Y-m-d H:i:s')) + ( get_option( 'gmt_offset' ) * 3600 );

This issue because of php timestamp function.

Change History (5)

#1 @dd32
7 years ago

  • Component changed from General to Date/Time
  • Description modified (diff)
  • Keywords reporter-feedback added

Hi @taojing10,

Can you clarify what issues you are seeing are?

time() is always expressed as a UTC offset, it's timezone independent. Theoretically, gmdate() should be returning the same date as time() is in your example here.

I suspect the situation you're experiencing may be a mismatch between server timezones and your PHP configuration, but it's not clear from your report if this is indeed the issue you're experiencing.

#2 @netweb
7 years ago

  • Summary changed from Fix Wordpress UCT Time not correct issue to Fix Wordpress UTC Time not correct issue

#3 @Rarst
7 years ago

  • Summary changed from Fix Wordpress UTC Time not correct issue to Fix WordPress UTC Time not correct issue

I would like to note that feeding timestamps into any date function that takes "fuzzy" input should not be done, because significant portion of timestamps is ambiguous for PHP date parser and will crash.

On ticket overall — not clear what is it the issue is and what is it trying to fix.

#4 @Rarst
7 years ago

Ah, wait, I didn't read gmdate() call there correctly. Still strtotime() and other freeform parsing is usually asking for trouble.

#5 @Rarst
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.