A Quick Introduction to WordPress’ Date/Time Component

At WordCamp Nordic’s contributor day I had the opportunity to chat with Andrey “Rarst” Savchenko about WordPress’ Date/Time component, the code that manages date, time, and timezone functionality. Savchenko is one of the maintainers of this lesser-known component, which includes code that dates back to PHP 4 times. After volunteering for years in the WordPress Stack Exchange forums, he encountered some of the worst Date/Time bugs, eventually spurring him on to get involved improving the code.

“From there it was a slow descent into the madness of the component,” Savchenko said. “Much of my experience ended up in my WpDateTime library. By last year I was, at last, confident I had a good grasp on the extent of the problem and a way forward for core.”

Date/Time issues affect both developers and users. Savchenko said most of the problems, by volume, are related to an incorrect output of localized time by `date_i18n()`. These things can trickle down to users and affect post scheduling, querying, and other operations.

“Some of them are outright bugs and some are easy to break due to incompatibility with Unix timestamps,” Savchenko said. “But many other parts of the core have problems related to time – most often around time zones and daylight savings time. Posts can end up with the wrong time, not published when needed, sorted in the wrong order, and so on.”

The requirement for backwards compatibility makes progress slow but Savchenko and fellow contributors shipped some of their work in the most recent release of WordPress. They will have more solutions available to pursue when the minimum required PHP version is bumped.

“In WordPress 5.1 we had shipped a set of important fixes for documentation and some of the worst bugs in `date_i18n()`.

“At the moment we continue to work on outstanding issues and get ready to implement a set of major new API functions. The work on the component has also revitalized the discussion of introducing user timezones. However I think those need a lot of UX work to reach workable proposal.”

Check out the video below for a quick overview of the work being done on the Date/Time component and find out how you can get involved at the #core-datetime channel in WordPress Slack.

Would you like to write for WP Tavern? We are always accepting guest posts from the community and are looking for new contributors. Get in touch with us and let's discuss your ideas.

2 Comments


  1. Perhaps there are flaws, but I mostly find the date/time system in WordPress works quite well.

    The human_time_diff() is particularly awesome :) That little function has saved me a ton of my own time in the past.

    Report


    1. Perhaps there are flaws, but I mostly find the date/time system in WordPress works quite well.

      It most certainly does not. When simply changing time zone in settings explodes time on every existing post that is… not remotely well. :)

      Report

Comments are closed.