public static function parseDate($date, $withtime = true, $timezone = null)
{
// strptime() is not available on Windows.
if (!function_exists('strptime')) {
return new Horde_Date($date, $timezone);
}
// strptime() is locale dependent, i.e. %p is not always matching
// AM/PM. Set the locale to C to workaround this, but grab the
// locale's D_FMT before that.
$format = Horde_Nls::getLangInfo(D_FMT);
if ($withtime) {
$format .= ' ' . ($GLOBALS['prefs']->getValue('twentyFour') ? '%H:%M' : '%I:%M %p');
}
$old_locale = setlocale(LC_TIME, 0);
setlocale(LC_TIME, 'C');
// Try exact format match first.
$date_arr = strptime($date, $format);
setlocale(LC_TIME, $old_locale);
if (!$date_arr) {
// Try with locale dependent parsing next.
$date_arr = strptime($date, $format);
if (!$date_arr) {
// Try throwing at Horde_Date finally.
return new Horde_Date($date, $timezone);
}
}
return new Horde_Date(array('year' => $date_arr['tm_year'] + 1900, 'month' => $date_arr['tm_mon'] + 1, 'mday' => $date_arr['tm_mday'], 'hour' => $date_arr['tm_hour'], 'min' => $date_arr['tm_min'], 'sec' => $date_arr['tm_sec']), $timezone);
}