[wp-hackers] Is today a new day?! - is_new_day()

Jeremy Clarke jer at simianuprising.com
Thu May 20 16:38:28 UTC 2010

On Thu, May 20, 2010 at 11:49 AM, Otto <otto at ottodestruct.com> wrote:
> Or you could use the_time(). Which is the same as the_date() but
> doesn't have the day logic.

If you do that then you need to manually specify the PHP date format
to be a date rather than the time. This makes no sense, ignores the
date format setting and completely ignores any filters attached to
the_date or get_the_date.

If I want to show a *date* I should not have to use a *time* function
with an override on the format to show as a *date*. To do so patently
weird and counter-intuitive.

the_date() and get_the_date() both use the default date format from
Settings > General, this is very important as that option has huge
effects on i18n of themes and on consistency of design. You can
manually fetch the setting and pass it to the_time(), but that is just
as weird and also not future-proof.

> If get_the_date() is ignoring the day logic, then that's a bug. It's
> supposed to do the same thing as the_date() in this respect.

I think that get_the_date() should match get_the_time(), which is a
much more sane function than the_date().

The real bug is that the_date() includes some very idiosyncratic and
unexpected behavior without any way to turn it off (see the ticket
above for a brief discussion of why adding an argument to turn it off
is awkward).

What would make sense is if the_date() and get_the_date() did what
you'd expect based on their names: get and show the date with no other
restrictions. If people want the weird once-per-day behavior they
*should* be using a seperate function, like the_date_once()
(hypothetical), or else use a conditional like:

if (is_new_day()) the_date();

I'm willing to concede that modifying date display to actually make
sense in WP is probably not worth it, as so many people are used to
the old system and most existing themes already take it for granted
(though I suspect that most theme authors were surprised when they
realized how it worked, and wouldn't have minded if the once-per-day
stuff had never been the default).

Making get_the_date() show the date without consideration for the
$previous_day stuff is exactly what should happen, especially because
it offers a sane workaround for the legacy strangeness of the_date().
Now when a theme author figures out what's happening and says "WTF
why?" they can at least look at the source of the_date() and see that
get_the_date() is there for them so they can harness the standard
settings (and filters!) for their dates without rewriting the_date()
entirely, which is what most people must be doing to show dates on all
posts inside the loop.

Jeremy Clarke
Code and Design | globalvoicesonline.org

More information about the wp-hackers mailing list