Make WordPress Core

Opened 7 years ago

Closed 6 years ago

#43269 closed defect (bug) (duplicate)

Get_The_Date return incorrect Unix Timestamp

Reported by: szarcensky's profile szarcensky Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.1
Component: Date/Time Keywords:
Focuses: Cc:

Description

When calling get_the_date('U'), the mysql2date() line $i = strtotime( $date ) defaults to GMT when no time zone is provided. However, the date it receives from get_post()->post_date is the local time zone with no time zone specified. As a result, the Unix timestamp returned is incorrect. For PST, the time is off by eight hours.

Change History (4)

#1 @soulseekah
7 years ago

This is interesting. Since Unix Epoch timestamps are in Coordinated Universal Time, assuming the post_date to be in UTC will yield an incorrect timestamp, offset by a predefined number of hours according to the set timezone.

One way would be to add a new case for 'U', but then what about 'r' and 'c'? Those would also be wrong, since they contain timezone information which would just be assumed as UTC. Same for 'e', 'I', 'O', 'P', 'T', 'Z' timezone identifiers, they'd all be incorrect.

What about mixtures thereof?

#2 @soulseekah
7 years ago

Other suggestions that spring to mind:

  1. We could limit the parameter to non-timezone-related ones.
  2. Use post_date_gmt and supply the timezone, which when formatted accordingly, will always work correctly.

#3 @Rarst
7 years ago

This is unfixable since other WP functions rely on receiving such incorrect "WordPress timestamp", most prominently date_i18n(). So it's a closed circle of incorrect output matching with incorrect input to produce "correct" result.

So this can be neither fixed or prevented from happening, without producing chain reaction of breakage.

Addressing this would take complete Date/Time component rewrite.

#4 @Rarst
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #44482.

Closing this in favor of more broad issue on WP timestamps. At the moment I envision we deprecate these formats in existing functions and introduce something explicit to work with unambiguous Unix timestamps.

Note: See TracTickets for help on using tickets.