Make WordPress Core

Opened 8 years ago

Last modified 4 years ago

#46210 new enhancement

Add helpers for default/empty datetime value

Reported by: johnjamesjacoby Owned by:
Priority: normal Milestone: Awaiting Review
Component: Database Version:
Severity: normal Keywords: has-patch
Cc: Focuses:

Description

Typing 0000-00-00 00:00:00 is error prone, and tedious.

There are a few dozen usages of it sprinkled through-out WordPress. Hundreds of plugins also.

I offer up the idea of 2 helper functions:

  • __return_empty_datetime() that simply returns 0000-00-00 00:00:00
  • is_empty_datetime( $datetime = '' ) to check if a variable is empty() or 0000-00-00 00:00:00

Change History (5)

#1 @johnjamesjacoby
8 years ago

Beware: the NO_ZERO_DATES MySQL mode rabbit hole is very deep.

WordPress doesn't use null as a default value in datetime columns for legacy reasons, and I'm not suggesting we try to support it here. Mostly, I am just sick of typing 0000-00-00 00:00:00 in my own related code, and rewriting the same helpers for avoiding empty datetime values.

#2 @johnbillion
8 years ago

  • Component Date/TimeDatabase
  • Keywords needs-patch added; 2nd-opinion removed
  • Type defect (bug)enhancement

+1

#3 @johnjamesjacoby
7 years ago

Somewhat related to #41785...

If there were such a helper function, it could include a MySQL version check, and own the default return value based on that and whatever MySQL modes happen to be set.

This ticket was mentioned in Slack in #core by jjj. View the logs.


6 years ago

This ticket was mentioned in PR #4130 on WordPress/wordpress-develop by @tabrisrp.


4 years ago
#5

  • Keywords has-patch added; needs-patch removed

Add helper functions for default datetime value and check for empty datetime value.

Trac ticket: https://core.trac.wordpress.org/ticket/46210

Note: See TracTickets for help on using tickets.