Make WordPress Core

Opened 10 years ago

Closed 6 years ago

#31809 closed defect (bug) (fixed)

get_date_from_gmt returns time=zero when timezone is not set

Reported by: goodevilgenius's profile goodevilgenius Owned by: sergeybiryukov's profile 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 6 years ago.
Needs wp_timezone() merged.

Download all attachments as: .zip

Change History (10)

#1 @SergeyBiryukov
10 years ago

  • Component changed from Formatting to Date/Time

#2 @SergeyBiryukov
10 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
10 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
7 years 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 "zero" 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?

Last edited 7 years ago by Rarst (previous) (diff)

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


7 years ago

@Rarst
6 years ago

Needs wp_timezone() merged.

#6 @Rarst
6 years 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.


6 years ago

#8 @SergeyBiryukov
6 years ago

  • Milestone changed from Awaiting Review to 5.3
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#9 @SergeyBiryukov
6 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 45887:

Date/Time: Rewrite and simplify get_gmt_from_date(), get_date_from_gmt(), and iso8601_to_datetime() using wp_timezone().

Improve unit test coverage.

Props Rarst, goodevilgenius.
Fixes #31809.

Note: See TracTickets for help on using tickets.