/** * DateTime homebrew parser * * Since some OSes and PHP versions (please upgrade to 5.3!) do not support built-in parsing functions, * we have to restort to this ugliness. * @internal * @param string $time Time formatted string * @param string $format Format, as accepted by strptime() * @return array Parsed parts */ protected function _strptime($time, $format) { $data = self::$data_init; if (empty(self::$strptime_short_mon)) { self::$strptime_short_mon = array_flip($this->_getStrings('dom_cal_month')); unset(self::$strptime_short_mon[""]); } if (empty(self::$strptime_long_mon)) { self::$strptime_long_mon = array_flip($this->_getStrings('dom_cal_month_long')); unset(self::$strptime_long_mon[""]); } $regexp = TimeDate::get_regular_expression($format); if (!preg_match('@' . $regexp['format'] . '@', $time, $dateparts)) { return false; } foreach (self::$parts_match as $part => $datapart) { if (isset($regexp['positions'][$part]) && isset($dateparts[$regexp['positions'][$part]])) { $data[$datapart] = (int) $dateparts[$regexp['positions'][$part]]; } } // now process non-numeric ones if (isset($regexp['positions']['F']) && !empty($dateparts[$regexp['positions']['F']])) { // FIXME: locale? $mon = $dateparts[$regexp['positions']['F']]; if (isset(self::$sugar_strptime_long_mon[$mon])) { $data["tm_mon"] = self::$sugar_strptime_long_mon[$mon]; } else { return false; } } if (isset($regexp['positions']['M']) && !empty($dateparts[$regexp['positions']['M']])) { // FIXME: locale? $mon = $dateparts[$regexp['positions']['M']]; if (isset(self::$sugar_strptime_short_mon[$mon])) { $data["tm_mon"] = self::$sugar_strptime_short_mon[$mon]; } else { return false; } } if (isset($regexp['positions']['a']) && !empty($dateparts[$regexp['positions']['a']])) { $ampm = trim($dateparts[$regexp['positions']['a']]); if ($ampm == 'pm') { if ($data["tm_hour"] != 12) { $data["tm_hour"] += 12; } } else { if ($ampm == 'am') { if ($data["tm_hour"] == 12) { // 12:00am is 00:00 $data["tm_hour"] = 0; } } else { return false; } } } if (isset($regexp['positions']['A']) && !empty($dateparts[$regexp['positions']['A']])) { $ampm = trim($dateparts[$regexp['positions']['A']]); if ($ampm == 'PM') { if ($data["tm_hour"] != 12) { $data["tm_hour"] += 12; } } else { if ($ampm == 'AM') { if ($data["tm_hour"] == 12) { // 12:00am is 00:00 $data["tm_hour"] = 0; } } else { return false; } } } return $data; }