SimplePie_Parse_Date

Date Parser.

Defined (1)

The class is defined in the following location(s).

/wp-includes/SimplePie/Parse/Date.php  
  1. class SimplePie_Parse_Date 
  2. /** 
  3. * Input data 
  4. * @access protected 
  5. * @var string 
  6. */ 
  7. var $date; 
  8.  
  9. /** 
  10. * List of days, calendar day name => ordinal day number in the week 
  11. * @access protected 
  12. * @var array 
  13. */ 
  14. var $day = array( 
  15. // English 
  16. 'mon' => 1,  
  17. 'monday' => 1,  
  18. 'tue' => 2,  
  19. 'tuesday' => 2,  
  20. 'wed' => 3,  
  21. 'wednesday' => 3,  
  22. 'thu' => 4,  
  23. 'thursday' => 4,  
  24. 'fri' => 5,  
  25. 'friday' => 5,  
  26. 'sat' => 6,  
  27. 'saturday' => 6,  
  28. 'sun' => 7,  
  29. 'sunday' => 7,  
  30. // Dutch 
  31. 'maandag' => 1,  
  32. 'dinsdag' => 2,  
  33. 'woensdag' => 3,  
  34. 'donderdag' => 4,  
  35. 'vrijdag' => 5,  
  36. 'zaterdag' => 6,  
  37. 'zondag' => 7,  
  38. // French 
  39. 'lundi' => 1,  
  40. 'mardi' => 2,  
  41. 'mercredi' => 3,  
  42. 'jeudi' => 4,  
  43. 'vendredi' => 5,  
  44. 'samedi' => 6,  
  45. 'dimanche' => 7,  
  46. // German 
  47. 'montag' => 1,  
  48. 'dienstag' => 2,  
  49. 'mittwoch' => 3,  
  50. 'donnerstag' => 4,  
  51. 'freitag' => 5,  
  52. 'samstag' => 6,  
  53. 'sonnabend' => 6,  
  54. 'sonntag' => 7,  
  55. // Italian 
  56. 'luned' => 1,  
  57. 'marted' => 2,  
  58. 'mercoled' => 3,  
  59. 'gioved' => 4,  
  60. 'venerd' => 5,  
  61. 'sabato' => 6,  
  62. 'domenica' => 7,  
  63. // Spanish 
  64. 'lunes' => 1,  
  65. 'martes' => 2,  
  66. 'mircoles' => 3,  
  67. 'jueves' => 4,  
  68. 'viernes' => 5,  
  69. 'sbado' => 6,  
  70. 'domingo' => 7,  
  71. // Finnish 
  72. 'maanantai' => 1,  
  73. 'tiistai' => 2,  
  74. 'keskiviikko' => 3,  
  75. 'torstai' => 4,  
  76. 'perjantai' => 5,  
  77. 'lauantai' => 6,  
  78. 'sunnuntai' => 7,  
  79. // Hungarian 
  80. 'htf*' => 1,  
  81. 'kedd' => 2,  
  82. 'szerda' => 3,  
  83. 'cstrtok' => 4,  
  84. 'pntek' => 5,  
  85. 'szombat' => 6,  
  86. 'vasrnap' => 7,  
  87. // Greek 
  88. '***' => 1,  
  89. '***' => 2,  
  90. '***' => 3,  
  91. '***' => 4,  
  92. '***' => 5,  
  93. '***' => 6,  
  94. '***' => 7,  
  95. ); 
  96.  
  97. /** 
  98. * List of months, calendar month name => calendar month number 
  99. * @access protected 
  100. * @var array 
  101. */ 
  102. var $month = array( 
  103. // English 
  104. 'jan' => 1,  
  105. 'january' => 1,  
  106. 'feb' => 2,  
  107. 'february' => 2,  
  108. 'mar' => 3,  
  109. 'march' => 3,  
  110. 'apr' => 4,  
  111. 'april' => 4,  
  112. 'may' => 5,  
  113. // No long form of May 
  114. 'jun' => 6,  
  115. 'june' => 6,  
  116. 'jul' => 7,  
  117. 'july' => 7,  
  118. 'aug' => 8,  
  119. 'august' => 8,  
  120. 'sep' => 9,  
  121. 'september' => 8,  
  122. 'oct' => 10,  
  123. 'october' => 10,  
  124. 'nov' => 11,  
  125. 'november' => 11,  
  126. 'dec' => 12,  
  127. 'december' => 12,  
  128. // Dutch 
  129. 'januari' => 1,  
  130. 'februari' => 2,  
  131. 'maart' => 3,  
  132. 'april' => 4,  
  133. 'mei' => 5,  
  134. 'juni' => 6,  
  135. 'juli' => 7,  
  136. 'augustus' => 8,  
  137. 'september' => 9,  
  138. 'oktober' => 10,  
  139. 'november' => 11,  
  140. 'december' => 12,  
  141. // French 
  142. 'janvier' => 1,  
  143. 'fvrier' => 2,  
  144. 'mars' => 3,  
  145. 'avril' => 4,  
  146. 'mai' => 5,  
  147. 'juin' => 6,  
  148. 'juillet' => 7,  
  149. 'aot' => 8,  
  150. 'septembre' => 9,  
  151. 'octobre' => 10,  
  152. 'novembre' => 11,  
  153. 'dcembre' => 12,  
  154. // German 
  155. 'januar' => 1,  
  156. 'februar' => 2,  
  157. 'mrz' => 3,  
  158. 'april' => 4,  
  159. 'mai' => 5,  
  160. 'juni' => 6,  
  161. 'juli' => 7,  
  162. 'august' => 8,  
  163. 'september' => 9,  
  164. 'oktober' => 10,  
  165. 'november' => 11,  
  166. 'dezember' => 12,  
  167. // Italian 
  168. 'gennaio' => 1,  
  169. 'febbraio' => 2,  
  170. 'marzo' => 3,  
  171. 'aprile' => 4,  
  172. 'maggio' => 5,  
  173. 'giugno' => 6,  
  174. 'luglio' => 7,  
  175. 'agosto' => 8,  
  176. 'settembre' => 9,  
  177. 'ottobre' => 10,  
  178. 'novembre' => 11,  
  179. 'dicembre' => 12,  
  180. // Spanish 
  181. 'enero' => 1,  
  182. 'febrero' => 2,  
  183. 'marzo' => 3,  
  184. 'abril' => 4,  
  185. 'mayo' => 5,  
  186. 'junio' => 6,  
  187. 'julio' => 7,  
  188. 'agosto' => 8,  
  189. 'septiembre' => 9,  
  190. 'setiembre' => 9,  
  191. 'octubre' => 10,  
  192. 'noviembre' => 11,  
  193. 'diciembre' => 12,  
  194. // Finnish 
  195. 'tammikuu' => 1,  
  196. 'helmikuu' => 2,  
  197. 'maaliskuu' => 3,  
  198. 'huhtikuu' => 4,  
  199. 'toukokuu' => 5,  
  200. 'keskuu' => 6,  
  201. 'heinkuu' => 7,  
  202. 'elokuu' => 8,  
  203. 'suuskuu' => 9,  
  204. 'lokakuu' => 10,  
  205. 'marras' => 11,  
  206. 'joulukuu' => 12,  
  207. // Hungarian 
  208. 'janur' => 1,  
  209. 'februr' => 2,  
  210. 'mrcius' => 3,  
  211. 'prilis' => 4,  
  212. 'mjus' => 5,  
  213. 'jnius' => 6,  
  214. 'jlius' => 7,  
  215. 'augusztus' => 8,  
  216. 'szeptember' => 9,  
  217. 'oktber' => 10,  
  218. 'november' => 11,  
  219. 'december' => 12,  
  220. // Greek 
  221. '***' => 1,  
  222. '***' => 2,  
  223. '***' => 3,  
  224. '***' => 3,  
  225. '***' => 4,  
  226. '***' => 5,  
  227. '***' => 5,  
  228. '***' => 5,  
  229. '****' => 6,  
  230. '***' => 6,  
  231. '****' => 7,  
  232. '***' => 7,  
  233. '***' => 8,  
  234. '***' => 8,  
  235. '***' => 9,  
  236. '***' => 10,  
  237. '***' => 11,  
  238. '***' => 12,  
  239. ); 
  240.  
  241. /** 
  242. * List of timezones, abbreviation => offset from UTC 
  243. * @access protected 
  244. * @var array 
  245. */ 
  246. var $timezone = array( 
  247. 'ACDT' => 37800,  
  248. 'ACIT' => 28800,  
  249. 'ACST' => 34200,  
  250. 'ACT' => -18000,  
  251. 'ACWDT' => 35100,  
  252. 'ACWST' => 31500,  
  253. 'AEDT' => 39600,  
  254. 'AEST' => 36000,  
  255. 'AFT' => 16200,  
  256. 'AKDT' => -28800,  
  257. 'AKST' => -32400,  
  258. 'AMDT' => 18000,  
  259. 'AMT' => -14400,  
  260. 'ANAST' => 46800,  
  261. 'ANAT' => 43200,  
  262. 'ART' => -10800,  
  263. 'AZOST' => -3600,  
  264. 'AZST' => 18000,  
  265. 'AZT' => 14400,  
  266. 'BIOT' => 21600,  
  267. 'BIT' => -43200,  
  268. 'BOT' => -14400,  
  269. 'BRST' => -7200,  
  270. 'BRT' => -10800,  
  271. 'BST' => 3600,  
  272. 'BTT' => 21600,  
  273. 'CAST' => 18000,  
  274. 'CAT' => 7200,  
  275. 'CCT' => 23400,  
  276. 'CDT' => -18000,  
  277. 'CEDT' => 7200,  
  278. 'CEST' => 7200,  
  279. 'CET' => 3600,  
  280. 'CGST' => -7200,  
  281. 'CGT' => -10800,  
  282. 'CHADT' => 49500,  
  283. 'CHAST' => 45900,  
  284. 'CIST' => -28800,  
  285. 'CKT' => -36000,  
  286. 'CLDT' => -10800,  
  287. 'CLST' => -14400,  
  288. 'COT' => -18000,  
  289. 'CST' => -21600,  
  290. 'CVT' => -3600,  
  291. 'CXT' => 25200,  
  292. 'DAVT' => 25200,  
  293. 'DTAT' => 36000,  
  294. 'EADT' => -18000,  
  295. 'EAST' => -21600,  
  296. 'EAT' => 10800,  
  297. 'ECT' => -18000,  
  298. 'EDT' => -14400,  
  299. 'EEST' => 10800,  
  300. 'EET' => 7200,  
  301. 'EGT' => -3600,  
  302. 'EKST' => 21600,  
  303. 'EST' => -18000,  
  304. 'FJT' => 43200,  
  305. 'FKDT' => -10800,  
  306. 'FKST' => -14400,  
  307. 'FNT' => -7200,  
  308. 'GALT' => -21600,  
  309. 'GEDT' => 14400,  
  310. 'GEST' => 10800,  
  311. 'GFT' => -10800,  
  312. 'GILT' => 43200,  
  313. 'GIT' => -32400,  
  314. 'GST' => 14400,  
  315. 'GST' => -7200,  
  316. 'GYT' => -14400,  
  317. 'HAA' => -10800,  
  318. 'HAC' => -18000,  
  319. 'HADT' => -32400,  
  320. 'HAE' => -14400,  
  321. 'HAP' => -25200,  
  322. 'HAR' => -21600,  
  323. 'HAST' => -36000,  
  324. 'HAT' => -9000,  
  325. 'HAY' => -28800,  
  326. 'HKST' => 28800,  
  327. 'HMT' => 18000,  
  328. 'HNA' => -14400,  
  329. 'HNC' => -21600,  
  330. 'HNE' => -18000,  
  331. 'HNP' => -28800,  
  332. 'HNR' => -25200,  
  333. 'HNT' => -12600,  
  334. 'HNY' => -32400,  
  335. 'IRDT' => 16200,  
  336. 'IRKST' => 32400,  
  337. 'IRKT' => 28800,  
  338. 'IRST' => 12600,  
  339. 'JFDT' => -10800,  
  340. 'JFST' => -14400,  
  341. 'JST' => 32400,  
  342. 'KGST' => 21600,  
  343. 'KGT' => 18000,  
  344. 'KOST' => 39600,  
  345. 'KOVST' => 28800,  
  346. 'KOVT' => 25200,  
  347. 'KRAST' => 28800,  
  348. 'KRAT' => 25200,  
  349. 'KST' => 32400,  
  350. 'LHDT' => 39600,  
  351. 'LHST' => 37800,  
  352. 'LINT' => 50400,  
  353. 'LKT' => 21600,  
  354. 'MAGST' => 43200,  
  355. 'MAGT' => 39600,  
  356. 'MAWT' => 21600,  
  357. 'MDT' => -21600,  
  358. 'MESZ' => 7200,  
  359. 'MEZ' => 3600,  
  360. 'MHT' => 43200,  
  361. 'MIT' => -34200,  
  362. 'MNST' => 32400,  
  363. 'MSDT' => 14400,  
  364. 'MSST' => 10800,  
  365. 'MST' => -25200,  
  366. 'MUT' => 14400,  
  367. 'MVT' => 18000,  
  368. 'MYT' => 28800,  
  369. 'NCT' => 39600,  
  370. 'NDT' => -9000,  
  371. 'NFT' => 41400,  
  372. 'NMIT' => 36000,  
  373. 'NOVST' => 25200,  
  374. 'NOVT' => 21600,  
  375. 'NPT' => 20700,  
  376. 'NRT' => 43200,  
  377. 'NST' => -12600,  
  378. 'NUT' => -39600,  
  379. 'NZDT' => 46800,  
  380. 'NZST' => 43200,  
  381. 'OMSST' => 25200,  
  382. 'OMST' => 21600,  
  383. 'PDT' => -25200,  
  384. 'PET' => -18000,  
  385. 'PETST' => 46800,  
  386. 'PETT' => 43200,  
  387. 'PGT' => 36000,  
  388. 'PHOT' => 46800,  
  389. 'PHT' => 28800,  
  390. 'PKT' => 18000,  
  391. 'PMDT' => -7200,  
  392. 'PMST' => -10800,  
  393. 'PONT' => 39600,  
  394. 'PST' => -28800,  
  395. 'PWT' => 32400,  
  396. 'PYST' => -10800,  
  397. 'PYT' => -14400,  
  398. 'RET' => 14400,  
  399. 'ROTT' => -10800,  
  400. 'SAMST' => 18000,  
  401. 'SAMT' => 14400,  
  402. 'SAST' => 7200,  
  403. 'SBT' => 39600,  
  404. 'SCDT' => 46800,  
  405. 'SCST' => 43200,  
  406. 'SCT' => 14400,  
  407. 'SEST' => 3600,  
  408. 'SGT' => 28800,  
  409. 'SIT' => 28800,  
  410. 'SRT' => -10800,  
  411. 'SST' => -39600,  
  412. 'SYST' => 10800,  
  413. 'SYT' => 7200,  
  414. 'TFT' => 18000,  
  415. 'THAT' => -36000,  
  416. 'TJT' => 18000,  
  417. 'TKT' => -36000,  
  418. 'TMT' => 18000,  
  419. 'TOT' => 46800,  
  420. 'TPT' => 32400,  
  421. 'TRUT' => 36000,  
  422. 'TVT' => 43200,  
  423. 'TWT' => 28800,  
  424. 'UYST' => -7200,  
  425. 'UYT' => -10800,  
  426. 'UZT' => 18000,  
  427. 'VET' => -14400,  
  428. 'VLAST' => 39600,  
  429. 'VLAT' => 36000,  
  430. 'VOST' => 21600,  
  431. 'VUT' => 39600,  
  432. 'WAST' => 7200,  
  433. 'WAT' => 3600,  
  434. 'WDT' => 32400,  
  435. 'WEST' => 3600,  
  436. 'WFT' => 43200,  
  437. 'WIB' => 25200,  
  438. 'WIT' => 32400,  
  439. 'WITA' => 28800,  
  440. 'WKST' => 18000,  
  441. 'WST' => 28800,  
  442. 'YAKST' => 36000,  
  443. 'YAKT' => 32400,  
  444. 'YAPT' => 36000,  
  445. 'YEKST' => 21600,  
  446. 'YEKT' => 18000,  
  447. ); 
  448.  
  449. /** 
  450. * Cached PCRE for SimplePie_Parse_Date::$day 
  451. * @access protected 
  452. * @var string 
  453. */ 
  454. var $day_pcre; 
  455.  
  456. /** 
  457. * Cached PCRE for SimplePie_Parse_Date::$month 
  458. * @access protected 
  459. * @var string 
  460. */ 
  461. var $month_pcre; 
  462.  
  463. /** 
  464. * Array of user-added callback methods 
  465. * @access private 
  466. * @var array 
  467. */ 
  468. var $built_in = array(); 
  469.  
  470. /** 
  471. * Array of user-added callback methods 
  472. * @access private 
  473. * @var array 
  474. */ 
  475. var $user = array(); 
  476.  
  477. /** 
  478. * Create new SimplePie_Parse_Date object, and set self::day_pcre,  
  479. * self::month_pcre, and self::built_in 
  480. * @access private 
  481. */ 
  482. public function __construct() 
  483. $this->day_pcre = '(' . implode(array_keys($this->day), '|') . ')'; 
  484. $this->month_pcre = '(' . implode(array_keys($this->month), '|') . ')'; 
  485.  
  486. static $cache; 
  487. if (!isset($cache[get_class($this)])) 
  488. $all_methods = get_class_methods($this); 
  489.  
  490. foreach ($all_methods as $method) 
  491. if (strtolower(substr($method, 0, 5)) === 'date_') 
  492. $cache[get_class($this)][] = $method; 
  493.  
  494. foreach ($cache[get_class($this)] as $method) 
  495. $this->built_in[] = $method; 
  496.  
  497. /** 
  498. * Get the object 
  499. * @access public 
  500. */ 
  501. public static function get() 
  502. static $object; 
  503. if (!$object) 
  504. $object = new SimplePie_Parse_Date; 
  505. return $object; 
  506.  
  507. /** 
  508. * Parse a date 
  509. * @final 
  510. * @access public 
  511. * @param string $date Date to parse 
  512. * @return int Timestamp corresponding to date string, or false on failure 
  513. */ 
  514. public function parse($date) 
  515. foreach ($this->user as $method) 
  516. if (($returned = call_user_func($method, $date)) !== false) 
  517. return $returned; 
  518.  
  519. foreach ($this->built_in as $method) 
  520. if (($returned = call_user_func(array($this, $method), $date)) !== false) 
  521. return $returned; 
  522.  
  523. return false; 
  524.  
  525. /** 
  526. * Add a callback method to parse a date 
  527. * @final 
  528. * @access public 
  529. * @param callable $callback 
  530. */ 
  531. public function add_callback($callback) 
  532. if (is_callable($callback)) 
  533. $this->user[] = $callback; 
  534. else 
  535. trigger_error('User-supplied function must be a valid callback', E_USER_WARNING); 
  536.  
  537. /** 
  538. * Parse a superset of W3C-DTF (allows hyphens and colons to be omitted, as 
  539. * well as allowing any of upper or lower case "T", horizontal tabs, or 
  540. * spaces to be used as the time seperator (including more than one)) 
  541. * @access protected 
  542. * @return int Timestamp 
  543. */ 
  544. public function date_w3cdtf($date) 
  545. static $pcre; 
  546. if (!$pcre) 
  547. $year = '([0-9]{4})'; 
  548. $month = $day = $hour = $minute = $second = '([0-9]{2})'; 
  549. $decimal = '([0-9]*)'; 
  550. $zone = '(?:(Z)|([+\-])([0-9]{1, 2}):?([0-9]{1, 2}))'; 
  551. $pcre = '/^' . $year . '(?:-?' . $month . '(?:-?' . $day . '(?:[Tt\x09\x20]+' . $hour . '(?::?' . $minute . '(?::?' . $second . '(?:.' . $decimal . ')?)?)?' . $zone . ')?)?)?$/'; 
  552. if (preg_match($pcre, $date, $match)) 
  553. /** 
  554. Capturing subpatterns: 
  555. 1: Year 
  556. 2: Month 
  557. 3: Day 
  558. 4: Hour 
  559. 5: Minute 
  560. 6: Second 
  561. 7: Decimal fraction of a second 
  562. 8: Zulu 
  563. 9: Timezone  
  564. 10: Timezone hours 
  565. 11: Timezone minutes 
  566. */ 
  567.  
  568. // Fill in empty matches 
  569. for ($i = count($match); $i <= 3; $i++) 
  570. $match[$i] = '1'; 
  571.  
  572. for ($i = count($match); $i <= 7; $i++) 
  573. $match[$i] = '0'; 
  574.  
  575. // Numeric timezone 
  576. if (isset($match[9]) && $match[9] !== '') 
  577. $timezone = $match[10] * 3600; 
  578. $timezone += $match[11] * 60; 
  579. if ($match[9] === '-') 
  580. $timezone = 0 - $timezone; 
  581. else 
  582. $timezone = 0; 
  583.  
  584. // Convert the number of seconds to an integer, taking decimals into account 
  585. $second = round($match[6] + $match[7] / pow(10, strlen($match[7]))); 
  586.  
  587. return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone; 
  588. else 
  589. return false; 
  590.  
  591. /** 
  592. * Remove RFC822 comments 
  593. * @access protected 
  594. * @param string $data Data to strip comments from 
  595. * @return string Comment stripped string 
  596. */ 
  597. public function remove_rfc2822_comments($string) 
  598. $string = (string) $string; 
  599. $position = 0; 
  600. $length = strlen($string); 
  601. $depth = 0; 
  602.  
  603. $output = ''; 
  604.  
  605. while ($position < $length && ($pos = strpos($string, '(', $position)) !== false) 
  606. $output .= substr($string, $position, $pos - $position); 
  607. $position = $pos + 1; 
  608. if ($string[$pos - 1] !== '\\') 
  609. $depth++; 
  610. while ($depth && $position < $length) 
  611. $position += strcspn($string, '()', $position); 
  612. if ($string[$position - 1] === '\\') 
  613. $position++; 
  614. continue; 
  615. elseif (isset($string[$position])) 
  616. switch ($string[$position]) 
  617. case '(': 
  618. $depth++; 
  619. break; 
  620.  
  621. case ')': 
  622. $depth--; 
  623. break; 
  624. $position++; 
  625. else 
  626. break; 
  627. else 
  628. $output .= '('; 
  629. $output .= substr($string, $position); 
  630.  
  631. return $output; 
  632.  
  633. /** 
  634. * Parse RFC2822's date format 
  635. * @access protected 
  636. * @return int Timestamp 
  637. */ 
  638. public function date_rfc2822($date) 
  639. static $pcre; 
  640. if (!$pcre) 
  641. $wsp = '[\x09\x20]'; 
  642. $fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)'; 
  643. $optional_fws = $fws . '?'; 
  644. $day_name = $this->day_pcre; 
  645. $month = $this->month_pcre; 
  646. $day = '([0-9]{1, 2})'; 
  647. $hour = $minute = $second = '([0-9]{2})'; 
  648. $year = '([0-9]{2, 4})'; 
  649. $num_zone = '([+\-])([0-9]{2})([0-9]{2})'; 
  650. $character_zone = '([A-Z]{1, 5})'; 
  651. $zone = '(?:' . $num_zone . '|' . $character_zone . ')'; 
  652. $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'; 
  653. if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match)) 
  654. /** 
  655. Capturing subpatterns: 
  656. 1: Day name 
  657. 2: Day 
  658. 3: Month 
  659. 4: Year 
  660. 5: Hour 
  661. 6: Minute 
  662. 7: Second 
  663. 8: Timezone  
  664. 9: Timezone hours 
  665. 10: Timezone minutes 
  666. 11: Alphabetic timezone 
  667. */ 
  668.  
  669. // Find the month number 
  670. $month = $this->month[strtolower($match[3])]; 
  671.  
  672. // Numeric timezone 
  673. if ($match[8] !== '') 
  674. $timezone = $match[9] * 3600; 
  675. $timezone += $match[10] * 60; 
  676. if ($match[8] === '-') 
  677. $timezone = 0 - $timezone; 
  678. // Character timezone 
  679. elseif (isset($this->timezone[strtoupper($match[11])])) 
  680. $timezone = $this->timezone[strtoupper($match[11])]; 
  681. // Assume everything else to be -0000 
  682. else 
  683. $timezone = 0; 
  684.  
  685. // Deal with 2/3 digit years 
  686. if ($match[4] < 50) 
  687. $match[4] += 2000; 
  688. elseif ($match[4] < 1000) 
  689. $match[4] += 1900; 
  690.  
  691. // Second is optional, if it is empty set it to zero 
  692. if ($match[7] !== '') 
  693. $second = $match[7]; 
  694. else 
  695. $second = 0; 
  696.  
  697. return gmmktime($match[5], $match[6], $second, $month, $match[2], $match[4]) - $timezone; 
  698. else 
  699. return false; 
  700.  
  701. /** 
  702. * Parse RFC850's date format 
  703. * @access protected 
  704. * @return int Timestamp 
  705. */ 
  706. public function date_rfc850($date) 
  707. static $pcre; 
  708. if (!$pcre) 
  709. $space = '[\x09\x20]+'; 
  710. $day_name = $this->day_pcre; 
  711. $month = $this->month_pcre; 
  712. $day = '([0-9]{1, 2})'; 
  713. $year = $hour = $minute = $second = '([0-9]{2})'; 
  714. $zone = '([A-Z]{1, 5})'; 
  715. $pcre = '/^' . $day_name . ', ' . $space . $day . '-' . $month . '-' . $year . $space . $hour . ':' . $minute . ':' . $second . $space . $zone . '$/i'; 
  716. if (preg_match($pcre, $date, $match)) 
  717. /** 
  718. Capturing subpatterns: 
  719. 1: Day name 
  720. 2: Day 
  721. 3: Month 
  722. 4: Year 
  723. 5: Hour 
  724. 6: Minute 
  725. 7: Second 
  726. 8: Timezone 
  727. */ 
  728.  
  729. // Month 
  730. $month = $this->month[strtolower($match[3])]; 
  731.  
  732. // Character timezone 
  733. if (isset($this->timezone[strtoupper($match[8])])) 
  734. $timezone = $this->timezone[strtoupper($match[8])]; 
  735. // Assume everything else to be -0000 
  736. else 
  737. $timezone = 0; 
  738.  
  739. // Deal with 2 digit year 
  740. if ($match[4] < 50) 
  741. $match[4] += 2000; 
  742. else 
  743. $match[4] += 1900; 
  744.  
  745. return gmmktime($match[5], $match[6], $match[7], $month, $match[2], $match[4]) - $timezone; 
  746. else 
  747. return false; 
  748.  
  749. /** 
  750. * Parse C99's asctime()'s date format 
  751. * @access protected 
  752. * @return int Timestamp 
  753. */ 
  754. public function date_asctime($date) 
  755. static $pcre; 
  756. if (!$pcre) 
  757. $space = '[\x09\x20]+'; 
  758. $wday_name = $this->day_pcre; 
  759. $mon_name = $this->month_pcre; 
  760. $day = '([0-9]{1, 2})'; 
  761. $hour = $sec = $min = '([0-9]{2})'; 
  762. $year = '([0-9]{4})'; 
  763. $terminator = '\x0A?\x00?'; 
  764. $pcre = '/^' . $wday_name . $space . $mon_name . $space . $day . $space . $hour . ':' . $min . ':' . $sec . $space . $year . $terminator . '$/i'; 
  765. if (preg_match($pcre, $date, $match)) 
  766. /** 
  767. Capturing subpatterns: 
  768. 1: Day name 
  769. 2: Month 
  770. 3: Day 
  771. 4: Hour 
  772. 5: Minute 
  773. 6: Second 
  774. 7: Year 
  775. */ 
  776.  
  777. $month = $this->month[strtolower($match[2])]; 
  778. return gmmktime($match[4], $match[5], $match[6], $month, $match[3], $match[7]); 
  779. else 
  780. return false; 
  781.  
  782. /** 
  783. * Parse dates using strtotime() 
  784. * @access protected 
  785. * @return int Timestamp 
  786. */ 
  787. public function date_strtotime($date) 
  788. $strtotime = strtotime($date); 
  789. if ($strtotime === -1 || $strtotime === false) 
  790. return false; 
  791. else 
  792. return $strtotime;