wppaste
WordPress

Date::date_w3cdtf( string $date ): int|false

Source
wp-includes/SimplePie/src/Parse/Date.php:643
Parse a superset of W3C-DTF (allows hyphens and colons to be omitted, as well as allowing any of upper or lower case "T", horizontal tabs, or spaces to be used as the time separator (including more than one))

Compatibility

WordPress
core
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$datestring

Return value

int|false
Timestamp

Performance profile

How much work a call to Date::date_w3cdtf() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
8–88

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 98.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What one call costs · 2 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost Date::date_w3cdtf() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!preg_match()8preg_match()
preg_match()66–88preg_match(), round(), gmmktime()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev988–8811
8.5988–8811
8.4988–8811
8.3988–8811
8.2988–8811
8.1988–88118 fewer instructions than PHP 7.4
7.41068–9611

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Source code

    public function date_w3cdtf(string $date)    {        $pcre = <<<'PCRE'            /            ^            (?P<year>[0-9]{4})            (?:                -?                (?P<month>[0-9]{2})                (?:                    -?                    (?P<day>[0-9]{2})                    (?:                        [Tt\x09\x20]+                        (?P<hour>[0-9]{2})                        (?:                            :?                            (?P<minute>[0-9]{2})                            (?:                                :?                                (?P<second>[0-9]{2})                                (?:                                    .                                    (?P<second_fraction>[0-9]*)                                )?                            )?                        )?                        (?:                            (?P<zulu>Z)                            |   (?P<tz_sign>[+\-])                                (?P<tz_hour>[0-9]{1,2})                                :?                                (?P<tz_minute>[0-9]{1,2})                        )                    )?                )?            )?            $            /xPCRE;        if (preg_match($pcre, $date, $match)) {            // Fill in empty matches and convert to proper types.            $year = (int) $match['year'];            $month = isset($match['month']) ? (int) $match['month'] : 1;            $day = isset($match['day']) ? (int) $match['day'] : 1;            $hour = isset($match['hour']) ? (int) $match['hour'] : 0;            $minute = isset($match['minute']) ? (int) $match['minute'] : 0;            $second = isset($match['second']) ? (int) $match['second'] : 0;            $second_fraction = isset($match['second_fraction']) ? ((int) $match['second_fraction']) / (10 ** strlen($match['second_fraction'])) : 0;            $tz_sign = ($match['tz_sign'] ?? '') === '-' ? -1 : 1;            $tz_hour = isset($match['tz_hour']) ? (int) $match['tz_hour'] : 0;            $tz_minute = isset($match['tz_minute']) ? (int) $match['tz_minute'] : 0;             // Numeric timezone            $timezone = $tz_hour * 3600;            $timezone += $tz_minute * 60;            $timezone *= $tz_sign;             // Convert the number of seconds to an integer, taking decimals into account            $second = (int) round($second + $second_fraction);             return gmmktime($hour, $minute, $second, $month, $day, $year) - $timezone;        }         return false;    }

Changelog

2 changes between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.9.7
Parameter $date retyped from untyped to string.verified against source
6.9.7
Return type changed from int to int|false.verified against source

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/SimplePie/src/Parse/Date.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.