WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 7 weeks ago

#31809 reviewing defect (bug)

get_date_from_gmt returns time=zero when timezone is not set

Reported by: goodevilgenius Owned by: SergeyBiryukov
Milestone: 5.3 Priority: normal
Severity: normal Version: 3.6
Component: Date/Time Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

when calling get_date_from_gmt(null) when the timezone is not set (i.e., get_option('timezone_string') returns null), the function returns Thu, 01 Jan 1970 00:00:00 +0000.

It should return the current time in the server's default timezone.

On line 2283 of formatting.php, we have this line:

return date( $format, 0 );

This should be replaced with:

return date( $format );

Attachments (1)

date-converting-functions.patch (9.8 KB) - added by Rarst 7 weeks ago.
Needs wp_timezone() merged.

Download all attachments as: .zip

Change History (9)

#1 @SergeyBiryukov
4 years ago

  • Component changed from Formatting to Date/Time

#2 @SergeyBiryukov
4 years ago

  • Version changed from 4.1.1 to 3.6

Introduced in [22435] for get_gmt_from_date(), copied to get_date_from_gmt() in [23618].

#3 @owencutajar
4 years ago

I get the same issue when timezone is set to UTC+0 .. function returns Thu, 01 Jan 1970 00:00:00 +0000 instead of current time.

#4 @Rarst
13 months ago

  • Keywords reporter-feedback added

I am hesitant about issue as reported. The function is clearly documented to accept non-nullable string in Y-m-d H:i:s format. Passing it null does not seem to be either explicitly or implicitly meaningful.

Returning current date is a case for invalid input, which is confusing as for me, but that's how it is written as of right now. I do not see how returning current time for invalid input is especially more meaningful or desired. It’s an error case. If anything it should probably fail altogether on it, but backwards compatibility.

What are the good reasons here to change behavior in such way?

Version 0, edited 13 months ago by Rarst (next)

This ticket was mentioned in Slack in #core-datetime by rarst. View the logs.


13 months ago

@Rarst
7 weeks ago

Needs wp_timezone() merged.

#6 @Rarst
7 weeks ago

  • Keywords has-patch has-unit-tests added; reporter-feedback removed

I have added unit tests and rewrote all three of date converting functions. They were definitely pretty broken before.

I've kept the "zero" date return case, because, well, it's in there and I don't know what out there might be possibly relying on it by now.

This ticket was mentioned in Slack in #core-datetime by rarst. View the logs.


7 weeks ago

#8 @SergeyBiryukov
7 weeks ago

  • Milestone changed from Awaiting Review to 5.3
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing
Note: See TracTickets for help on using tickets.