Skip to content

Commit 5464ea5

Browse files
committed
refactor: Use ext-Intl natively instead of strftime and remove any shim logic
1 parent dc4040d commit 5464ea5

22 files changed

Lines changed: 92 additions & 115 deletions

admin/index.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@
2121
'permission' => ['horde:administration'],
2222
]);
2323
require_once dirname(__DIR__) . '/rampage.php';
24-

admin/locks.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
use Horde\Core\Uri\UriBuilderInterface;
1616
use Horde\Util\Util;
1717

18-
use function PHP81_BC\strftime;
19-
2018
require_once __DIR__ . '/../lib/Application.php';
2119
Horde_Registry::appInit('horde', [
2220
'permission' => ['horde:administration:locks'],
@@ -54,8 +52,8 @@
5452
} else {
5553
$lock['scope'] = $lock['lock_scope'];
5654
}
57-
$lock['start'] = strftime($format, $lock['lock_update_timestamp']);
58-
$lock['end'] = strftime($format, $lock['lock_expiry_timestamp']);
55+
$lock['start'] = Horde\Date\Format::formatDate($lock['lock_update_timestamp'], $format, $GLOBALS['language'] ?? 'en_US');
56+
$lock['end'] = Horde\Date\Format::formatDate($lock['lock_expiry_timestamp'], $format, $GLOBALS['language'] ?? 'en_US');
5957
}
6058
$view->locks = $locks;
6159
$page_output->addScriptFile('tables.js', 'horde');

config/prefs.php

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
use function PHP81_BC\strftime;
3+
use Horde\Date\Format;
44

55
/**
66
* Preferences Information
@@ -427,77 +427,71 @@
427427
];
428428

429429
$_prefs['date_format'] = [
430-
'value' => '%x',
430+
'value' => 'short',
431431
'type' => 'enum',
432432
'enum' => [
433-
'%x' => strftime('%x'),
434-
'%Y-%m-%d' => strftime('%Y-%m-%d'),
435-
'%d/%m/%Y' => strftime('%d/%m/%Y'),
436-
'%A, %B %d, %Y' => strftime('%A, %B %d, %Y'),
437-
'%A, %d. %B %Y' => strftime('%A, %d. %B %Y'),
438-
'%A, %d %B %Y' => strftime('%A, %d %B %Y'),
439-
'%a, %b %e, %Y' => strftime('%a, %b %e, %Y'),
440-
'%a, %b %e, %y' => strftime('%a, %b %e, %y'),
441-
'%a, %b %e' => strftime('%a, %b %e'),
442-
'%a, %e %b %Y' => strftime('%a, %e %b %Y'),
443-
'%a, %e %b %y' => strftime('%a, %e %b %y'),
444-
'%a %d %b %Y' => strftime('%a %d %b %Y'),
445-
'%a %x' => strftime('%a %x'),
446-
'%a %Y-%m-%d' => strftime('%a %Y-%m-%d'),
447-
'%e %b %Y' => strftime('%e %b %Y'),
448-
'%e. %b %Y' => strftime('%e. %b %Y'),
449-
'%e. %m %Y' => strftime('%e %m %Y'),
450-
'%e. %m.' => strftime('%e. %m.'),
451-
'%e. %B' => strftime('%e. %B'),
452-
'%e. %B %Y' => strftime('%e. %B %Y'),
453-
'%e. %B %y' => strftime('%e. %B %y'),
454-
'%B %e, %Y' => strftime('%B %e, %Y'),
433+
'short' => Format::formatDate(time(), 'short', $GLOBALS['language'] ?? 'en_US'),
434+
'yyyy-MM-dd' => Format::formatDate(time(), 'yyyy-MM-dd', $GLOBALS['language'] ?? 'en_US'),
435+
'dd/MM/yyyy' => Format::formatDate(time(), 'dd/MM/yyyy', $GLOBALS['language'] ?? 'en_US'),
436+
'EEEE, MMMM dd, yyyy' => Format::formatDate(time(), 'EEEE, MMMM dd, yyyy', $GLOBALS['language'] ?? 'en_US'),
437+
'EEEE, dd. MMMM yyyy' => Format::formatDate(time(), 'EEEE, dd. MMMM yyyy', $GLOBALS['language'] ?? 'en_US'),
438+
'EEEE, dd MMMM yyyy' => Format::formatDate(time(), 'EEEE, dd MMMM yyyy', $GLOBALS['language'] ?? 'en_US'),
439+
'EEE, MMM d, yyyy' => Format::formatDate(time(), 'EEE, MMM d, yyyy', $GLOBALS['language'] ?? 'en_US'),
440+
'EEE, MMM d, yy' => Format::formatDate(time(), 'EEE, MMM d, yy', $GLOBALS['language'] ?? 'en_US'),
441+
'EEE, MMM d' => Format::formatDate(time(), 'EEE, MMM d', $GLOBALS['language'] ?? 'en_US'),
442+
'EEE, d MMM yyyy' => Format::formatDate(time(), 'EEE, d MMM yyyy', $GLOBALS['language'] ?? 'en_US'),
443+
'EEE, d MMM yy' => Format::formatDate(time(), 'EEE, d MMM yy', $GLOBALS['language'] ?? 'en_US'),
444+
'EEE dd MMM yyyy' => Format::formatDate(time(), 'EEE dd MMM yyyy', $GLOBALS['language'] ?? 'en_US'),
445+
'd MMM yyyy' => Format::formatDate(time(), 'd MMM yyyy', $GLOBALS['language'] ?? 'en_US'),
446+
'd. MMM yyyy' => Format::formatDate(time(), 'd. MMM yyyy', $GLOBALS['language'] ?? 'en_US'),
447+
'd. MM yyyy' => Format::formatDate(time(), 'd. MM yyyy', $GLOBALS['language'] ?? 'en_US'),
448+
'd. MM.' => Format::formatDate(time(), 'd. MM.', $GLOBALS['language'] ?? 'en_US'),
449+
'd. MMMM' => Format::formatDate(time(), 'd. MMMM', $GLOBALS['language'] ?? 'en_US'),
450+
'd. MMMM yyyy' => Format::formatDate(time(), 'd. MMMM yyyy', $GLOBALS['language'] ?? 'en_US'),
451+
'd. MMMM yy' => Format::formatDate(time(), 'd. MMMM yy', $GLOBALS['language'] ?? 'en_US'),
452+
'MMMM d, yyyy' => Format::formatDate(time(), 'MMMM d, yyyy', $GLOBALS['language'] ?? 'en_US'),
455453
],
456454
'desc' => _("Choose how to display dates (full format):"),
457455
];
458456

459457
$_prefs['date_format_mini'] = [
460-
'value' => '%x',
458+
'value' => 'short',
461459
'type' => 'enum',
462460
'enum' => [
463-
'%x' => strftime('%x'),
464-
'%Y-%m-%d' => strftime('%Y-%m-%d'),
465-
'%d/%m/%Y' => strftime('%d/%m/%Y'),
466-
'%a, %b %e, %Y' => strftime('%a, %b %e, %Y'),
467-
'%a, %b %e, %y' => strftime('%a, %b %e, %y'),
468-
'%a, %b %e' => strftime('%a, %b %e'),
469-
'%a, %e %b %Y' => strftime('%a, %e %b %Y'),
470-
'%a, %e %b %y' => strftime('%a, %e %b %y'),
471-
'%a %d %b %Y' => strftime('%a %d %b %Y'),
472-
'%a %x' => strftime('%a %x'),
473-
'%a %Y-%m-%d' => strftime('%a %Y-%m-%d'),
474-
'%e %b %Y' => strftime('%e %b %Y'),
475-
'%e. %b %Y' => strftime('%e. %b %Y'),
476-
'%e. %m %Y' => strftime('%e %m %Y'),
477-
'%e. %m.' => strftime('%e. %m.'),
478-
'%b %e, %Y' => strftime('%b %e, %Y'),
461+
'short' => Format::formatDate(time(), 'short', $GLOBALS['language'] ?? 'en_US'),
462+
'yyyy-MM-dd' => Format::formatDate(time(), 'yyyy-MM-dd', $GLOBALS['language'] ?? 'en_US'),
463+
'dd/MM/yyyy' => Format::formatDate(time(), 'dd/MM/yyyy', $GLOBALS['language'] ?? 'en_US'),
464+
'EEE, MMM d, yyyy' => Format::formatDate(time(), 'EEE, MMM d, yyyy', $GLOBALS['language'] ?? 'en_US'),
465+
'EEE, MMM d, yy' => Format::formatDate(time(), 'EEE, MMM d, yy', $GLOBALS['language'] ?? 'en_US'),
466+
'EEE, MMM d' => Format::formatDate(time(), 'EEE, MMM d', $GLOBALS['language'] ?? 'en_US'),
467+
'EEE, d MMM yyyy' => Format::formatDate(time(), 'EEE, d MMM yyyy', $GLOBALS['language'] ?? 'en_US'),
468+
'EEE, d MMM yy' => Format::formatDate(time(), 'EEE, d MMM yy', $GLOBALS['language'] ?? 'en_US'),
469+
'EEE dd MMM yyyy' => Format::formatDate(time(), 'EEE dd MMM yyyy', $GLOBALS['language'] ?? 'en_US'),
470+
'd MMM yyyy' => Format::formatDate(time(), 'd MMM yyyy', $GLOBALS['language'] ?? 'en_US'),
471+
'd. MMM yyyy' => Format::formatDate(time(), 'd. MMM yyyy', $GLOBALS['language'] ?? 'en_US'),
472+
'd. MM yyyy' => Format::formatDate(time(), 'd. MM yyyy', $GLOBALS['language'] ?? 'en_US'),
473+
'd. MM.' => Format::formatDate(time(), 'd. MM.', $GLOBALS['language'] ?? 'en_US'),
474+
'MMM d, yyyy' => Format::formatDate(time(), 'MMM d, yyyy', $GLOBALS['language'] ?? 'en_US'),
479475
],
480476
'desc' => _("Choose how to display dates (abbreviated format):"),
481477
];
482478

483479
$_prefs['time_format'] = [
484-
'value' => '%X',
480+
'value' => 'h:mm:ss a',
485481
'type' => 'enum',
486482
'enum' => [
487-
'%X' => strftime('%X') . ' (' . _("Default") . ')',
488-
'%H:%M:%S' => strftime('%H:%M:%S') . ' (' . _("24-hour format") . ')',
489-
'%l:%M:%S %p' => strftime('%l:%M:%S %p'),
483+
'h:mm:ss a' => Format::formatDate(time(), 'h:mm:ss a', $GLOBALS['language'] ?? 'en_US') . ' (' . _("Default") . ')',
484+
'HH:mm:ss' => Format::formatDate(time(), 'HH:mm:ss', $GLOBALS['language'] ?? 'en_US') . ' (' . _("24-hour format") . ')',
490485
],
491486
'desc' => _("Choose how to display times (full format):"),
492487
];
493488

494489
$_prefs['time_format_mini'] = [
495-
'value' => '%X',
490+
'value' => 'h:mm a',
496491
'type' => 'enum',
497492
'enum' => [
498-
'%X' => strftime('%X') . ' (' . _("Default") . ')',
499-
'%H:%M' => strftime('%H:%M') . ' (' . _("24-hour format") . ')',
500-
'%l:%M %p' => strftime('%l:%M %p'),
493+
'h:mm a' => Format::formatDate(time(), 'h:mm a', $GLOBALS['language'] ?? 'en_US') . ' (' . _("Default") . ')',
494+
'HH:mm' => Format::formatDate(time(), 'HH:mm', $GLOBALS['language'] ?? 'en_US') . ' (' . _("24-hour format") . ')',
501495
],
502496
'desc' => _("Choose how to display times (abbreviated format):"),
503497
];

lib/Ajax/Application/FacebookHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ protected function _error($e)
237237
{
238238
global $injector, $notification;
239239

240-
$injector->getInstance(\Psr\Log\LoggerInterface::class)->info(
240+
$injector->getInstance(Psr\Log\LoggerInterface::class)->info(
241241
($e instanceof Exception) ? $e->getMessage() : (string) $e,
242242
($e instanceof Exception) ? ['exception' => $e] : []
243243
);

lib/Ajax/Application/TwitterHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ protected function _twitterError($e)
277277
{
278278
global $injector, $notification;
279279

280-
$injector->getInstance(\Psr\Log\LoggerInterface::class)->info(
280+
$injector->getInstance(Psr\Log\LoggerInterface::class)->info(
281281
($e instanceof Exception) ? $e->getMessage() : (string) $e,
282282
($e instanceof Exception) ? ['exception' => $e] : []
283283
);

lib/Block/Account/Ldap.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
use function PHP81_BC\strftime;
4-
53
/**
64
* The ldap class attempts to return user information stored in an ldap
75
* directory service.
@@ -178,13 +176,14 @@ public function getShell()
178176
*/
179177
public function getPasswordChange()
180178
{
179+
$fmt = new IntlDateFormatter($GLOBALS['language'], IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
181180
$information = $this->_getAccount();
182181
try {
183-
return strftime('%x', $information->getValue('shadowlastchange', 'single') * 86400);
182+
return $fmt->format($information->getValue('shadowlastchange', 'single') * 86400);
184183
} catch (Horde_Ldap_Exception $e) {
185184
}
186185
try {
187-
return strftime('%x', $this->_convertWinTimeToUnix($information->getValue('pwdlastset', 'single')));
186+
return $fmt->format($this->_convertWinTimeToUnix($information->getValue('pwdlastset', 'single')));
188187
} catch (Horde_Ldap_Exception $e) {
189188
return '';
190189
}

lib/Block/Moon.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
use function PHP81_BC\strftime;
4-
53
/**
64
* @package Horde
75
*/
@@ -66,7 +64,7 @@ protected function _content()
6664
. '<tr><td colspan="4" class="control"><strong>' . $location . '</strong></td></tr>'
6765
. '<tr height="100%"><td width="25%" align="center">'
6866
. Horde_Themes_Image::tag('block/moon/newmoon.png', ['alt' => _("New Moon")])
69-
. '<br />' . strftime($GLOBALS['prefs']->getValue('date_format_mini'), $dates[0])
67+
. '<br />' . Horde\Date\Format::formatDate($dates[0], $GLOBALS['prefs']->getValue('date_format_mini'), $GLOBALS['language'] ?? 'en_US')
7068
. '</td>';
7169

7270
$html .= '<td width="25%" align="center">';
@@ -76,11 +74,11 @@ protected function _content()
7674
} else {
7775
$html .= Horde_Themes_Image::tag('block/moon/firstquarter.png', ['alt' => _("First Quarter")]);
7876
}
79-
$html .= '<br />' . strftime($GLOBALS['prefs']->getValue('date_format_mini'), $dates[1]) . '</td>';
77+
$html .= '<br />' . Horde\Date\Format::formatDate($dates[1], $GLOBALS['prefs']->getValue('date_format_mini'), $GLOBALS['language'] ?? 'en_US') . '</td>';
8078

8179
$html .= '<td width="25%" align="center">'
8280
. Horde_Themes_Image::tag('block/moon/fullmoon.png', ['alt' => _("Full Moon")])
83-
. '<br />' . strftime($GLOBALS['prefs']->getValue('date_format_mini'), $dates[2]) . '</td>';
81+
. '<br />' . Horde\Date\Format::formatDate($dates[2], $GLOBALS['prefs']->getValue('date_format_mini'), $GLOBALS['language'] ?? 'en_US') . '</td>';
8482

8583
$html .= '<td width="25%" align="center">';
8684
if (isset($this->_params['hemisphere'])
@@ -89,7 +87,7 @@ protected function _content()
8987
} else {
9088
$html .= Horde_Themes_Image::tag('block/moon/lastquarter.png', ['alt' => _("Last Quarter")]);
9189
}
92-
$html .= '<br />' . strftime($GLOBALS['prefs']->getValue('date_format_mini'), $dates[3]) . '</td></tr></table>';
90+
$html .= '<br />' . Horde\Date\Format::formatDate($dates[3], $GLOBALS['prefs']->getValue('date_format_mini'), $GLOBALS['language'] ?? 'en_US') . '</td></tr></table>';
9391

9492
return $html;
9593
}

lib/Block/Sunrise.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
use function PHP81_BC\strftime;
4-
53
/**
64
* @package Horde
75
*/
@@ -184,6 +182,6 @@ protected function _calculateSunset($date, $latitude, $longitude, $sunset, $time
184182
$V -= $min / 60;
185183
$sec = intval($V * 3600);
186184

187-
return strftime('%X', mktime($hour, $min, $sec, $mon, $mday, $year));
185+
return (new IntlDateFormatter($GLOBALS['language'], IntlDateFormatter::NONE, IntlDateFormatter::MEDIUM))->format(mktime($hour, $min, $sec, $mon, $mday, $year));
188186
}
189187
}

lib/Block/Time.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
use function PHP81_BC\strftime;
4-
53
/**
64
* @package Horde
75
*/
@@ -49,11 +47,11 @@ protected function _content()
4947
$GLOBALS['registry']->setTimeZone();
5048

5149
$html = '<div style="font-size:200%; font-weight:bold; text-align:center">'
52-
. strftime($GLOBALS['prefs']->getValue('date_format')) . ' ';
50+
. Horde\Date\Format::formatDate(time(), $GLOBALS['prefs']->getValue('date_format'), $GLOBALS['language'] ?? 'en_US') . ' ';
5351
if ($this->_params['time'] == '24-hour') {
54-
$html .= strftime('%H:%M');
52+
$html .= date('H:i');
5553
} else {
56-
$html .= strftime('%I:%M %p');
54+
$html .= date('g:i A');
5755
}
5856
return $html . '</div>';
5957
}

lib/Block/Vatid.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
use Horde\Util\Util;
55
use Horde\Util\Variables;
66

7-
use function PHP81_BC\strftime;
8-
97
/**
108
* @package Horde
119
*/
@@ -94,7 +92,7 @@ protected function _ajaxUpdate(Horde_Variables|Variables $vars)
9492
. $result->countryCode . '<br /><em>'
9593
. _("VAT number") . ':</em> ' . $result->vatNumber
9694
. '<br /><em>' . _("Date") . ':</em> '
97-
. strftime($GLOBALS['prefs']->getValue('date_format'), strtotime($result->requestDate))
95+
. Horde\Date\Format::formatDate(strtotime($result->requestDate), $GLOBALS['prefs']->getValue('date_format'), $GLOBALS['language'] ?? 'en_US')
9896
. '<br />';
9997

10098
if (!empty($result->name)) {

0 commit comments

Comments
 (0)