Make WordPress Core

Opened 9 years ago

Closed 8 years ago

#42451 closed defect (bug) (worksforme)

Fix WordPress UTC Time not correct issue

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

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
9 years ago

  • Component GeneralDate/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
9 years ago

  • Summary Fix Wordpress UCT Time not correct issueFix Wordpress UTC Time not correct issue

#3 @Rarst
8 years ago

  • Summary Fix Wordpress UTC Time not correct issueFix 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
8 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
8 years ago

  • Milestone Awaiting Review
  • Resolutionworksforme
  • Status newclosed
Note: See TracTickets for help on using tickets.