Date::date_rfc2822( string $date ): int|false
- Source
wp-includes/SimplePie/src/Parse/Date.php:766
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_rfc2822() 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
- Scaling
- Constant
- Instructions
- 13–94
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 105.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost Date::date_rfc2822() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!preg_match() | 13–40 | ->remove_rfc2822_comments(), preg_match() |
preg_match() && !isset($match) | 58–89 | ->remove_rfc2822_comments(), preg_match(), strtolower(), gmmktime() |
preg_match() && isset($match) | 63–94 | ->remove_rfc2822_comments(), preg_match(), strtolower(), strtoupper(), gmmktime() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 104 | 13–93 | 8 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 105 | 13–94 | 8 | |
| 8.4 | 105 | 13–94 | 8 | |
| 8.3 | 105 | 13–94 | 8 | |
| 8.2 | 105 | 13–94 | 8 | |
| 8.1 | 105 | 13–94 | 8 | |
| 7.4 | 105 | 13–94 | 8 |
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.
Uses · 1
- \SimplePie\Parse\Date::remove_rfc2822_comments()
Source code
public function date_rfc2822(string $date) { static $pcre; if (!$pcre) { $wsp = '[\x09\x20]'; $fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)'; $optional_fws = $fws . '?'; $day_name = $this->day_pcre; $month = $this->month_pcre; $day = '([0-9]{1,2})'; $hour = $minute = $second = '([0-9]{2})'; $year = '([0-9]{2,4})'; $num_zone = '([+\-])([0-9]{2})([0-9]{2})'; $character_zone = '([A-Z]{1,5})'; $zone = '(?:' . $num_zone . '|' . $character_zone . ')'; $pcre = '/(?:' . $optional_fws . $day_name . $optional_fws . ',)?' . $optional_fws . $day . $fws . $month . $fws . $year . $fws . $hour . $optional_fws . ':' . $optional_fws . $minute . '(?:' . $optional_fws . ':' . $optional_fws . $second . ')?' . $fws . $zone . '/i'; } if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match)) { /* Capturing subpatterns: 1: Day name 2: Day 3: Month 4: Year 5: Hour 6: Minute 7: Second 8: Timezone ± 9: Timezone hours 10: Timezone minutes 11: Alphabetic timezone */ $day = (int) $match[2]; // Find the month number $month = $this->month[strtolower($match[3])]; $year = (int) $match[4]; $hour = (int) $match[5]; $minute = (int) $match[6]; // Second is optional, if it is empty set it to zero $second = (int) $match[7]; $tz_sign = $match[8]; $tz_hour = (int) $match[9]; $tz_minute = (int) $match[10]; $tz_code = isset($match[11]) ? strtoupper($match[11]) : ''; // Numeric timezone if ($tz_sign !== '') { $timezone = $tz_hour * 3600; $timezone += $tz_minute * 60; if ($tz_sign === '-') { $timezone = 0 - $timezone; } } // Character timezone elseif (isset($this->timezone[$tz_code])) { $timezone = $this->timezone[$tz_code]; } // Assume everything else to be -0000 else { $timezone = 0; } // Deal with 2/3 digit years if ($year < 50) { $year += 2000; } elseif ($year < 1000) { $year += 1900; } return gmmktime($hour, $minute, $second, $month, $day, $year) - $timezone; } return false; }Changelog
2 changes between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$date retyped from untyped to string.verified against sourceint to int|false.verified against sourceAbout 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.