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: |
|
Owned by: |
|
---|---|---|---|
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)
Change History (10)
#3
@
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
@
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?
This ticket was mentioned in Slack in #core-datetime by rarst. View the logs.
7 years ago
#6
@
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.
Introduced in [22435] for
get_gmt_from_date()
, copied toget_date_from_gmt()
in [23618].