[wp-trac] [WordPress Trac] #37910: Remove confusing legacy logic in date_i18n()
WordPress Trac
noreply at wordpress.org
Thu Sep 1 19:08:50 UTC 2016
#37910: Remove confusing legacy logic in date_i18n()
-------------------------+-----------------------------
Reporter: jdgrimes | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Date/Time | Version: 3.0
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------------------
In #37634 it was pointed out that `date_i18n()` contains the following
line:
{{{#!php
$datefunc = $gmt? 'gmdate' : 'date';
}}}
However, there is actually no difference between `date()` and `gmdate()`
in WordPress, so that line can be removed. At the time that this logic was
added, WordPress was experimenting with setting the default PHP time based
on the site's timezone. But in the end it was decided to just always have
the default PHP timezome be UTC/GMT. Which means that `date()` and
`time()` always return UTC values, and thus using `gmdate()` is
unnecessary. (I discovered this just the other day when I was researching
a date/time-related bug in a plugin.) See #9588 and [12727].
Retaining this legacy logic is confusing, since it implies that there is
some difference in WordPress between using `date()` and `gmdate()`, when
there really is none. `date()` should just be used instead.
Note that although that particular line in the function is unnecessary,
the `$gmt` parameter is still needed for these lines:
{{{#!php
<?php
if ( false === $i ) {
if ( ! $gmt )
$i = current_time( 'timestamp' );
else
$i = time();
// we should not let date() interfere with our
// specially computed timestamp
$gmt = true;
}
}}}
However, they could be simplified to just:
{{{#!php
<?php
if ( false === $i ) {
$i = current_time( 'timestamp', $gmt );
}
}}}
We should probably consider removing every reference to `gmdate()` in core
in favor of just using `date()`, to avoid this confusion. But maybe that
would ultimately be for a separate ticket.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/37910>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list