Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion lib/Nag.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Horde\Util\Util;
use Horde\Date\Format;
use Horde\Date\Formatter\IcuFormatter;

/**
* Nag Base Class.
Expand Down Expand Up @@ -168,6 +169,36 @@ public static function secondsToString($seconds)
*/
public static function parseDate($date, $withtime = true)
{
$date = trim($date);
$dateFormat = $GLOBALS['prefs']->getValue('date_format_mini');
$locale = $GLOBALS['language'] ?? ($GLOBALS['prefs']->getValue('language') ?? 'en_US');

if (!Format::isStrftimeFormat($dateFormat)) {
try {
$formatter = new IcuFormatter();
if ($withtime && preg_match('/^(.+?)\s+(\S+)$/', $date, $parts)) {
$datePart = $formatter->parse($parts[1], $dateFormat, $locale);
$timeFormat = $GLOBALS['prefs']->getValue('twentyFour') ? 'HH:mm' : 'h:mm a';
$timePart = $formatter->parse($parts[2], $timeFormat, $locale);

return new Horde_Date(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use Horde\Date\Date instead?

['year' => (int) $datePart->format('Y'),
'month' => (int) $datePart->format('n'),
'mday' => (int) $datePart->format('j'),
'hour' => (int) $timePart->format('G'),
'min' => (int) $timePart->format('i'),
'sec' => 0]
);
}

$parsed = $formatter->parse($date, $dateFormat, $locale);

return new Horde_Date($parsed->getTimestamp());
} catch (Exception $e) {
// Fall through to legacy parsing.
}
}

// strptime() is not available on Windows.
if (!function_exists('strptime')) {
return new Horde_Date($date);
Expand All @@ -176,7 +207,7 @@ public static function parseDate($date, $withtime = true)
// 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 = $GLOBALS['prefs']->getValue('date_format_mini');
$format = $dateFormat;
if ($withtime) {
$format .= ' '
. ($GLOBALS['prefs']->getValue('twentyFour') ? '%H:%M' : '%I:%M %p');
Expand Down
Loading