Replaced strftime with IntlDateFormatter (#1286)

This commit is contained in:
Jenny Tam 2021-08-10 15:27:39 -07:00 committed by GitHub
parent fd48bcbf69
commit 656767aa16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 4 deletions

View file

@ -25,6 +25,22 @@ function printMoney($amt, $info)
echo PHP_EOL;
}
function printCal($date)
{
$loc = setlocale(LC_TIME, 0);
$fmt = datefmt_create(
$loc,
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
datefmt_set_pattern($fmt, 'cccc');
echo datefmt_format($fmt, $date) . PHP_EOL;
datefmt_set_pattern($fmt, 'MMMM');
echo datefmt_format($fmt, $date) . PHP_EOL;
}
require_once('MsSetup.inc');
$setLocaleInfo = ($_SERVER['argv'][1]);
@ -90,8 +106,8 @@ if ($sep !== $info['thousands_sep']) {
$n1 = 10000.98765;
printMoney($n1, $info);
echo strftime("%A", strtotime("12/25/2020")) . PHP_EOL;
echo strftime("%B", strtotime("12/25/2020")) . PHP_EOL;
$d = new DateTime("12/25/2020", new DateTimeZone('America/Los_Angeles'));
printCal($d);
try {
$conn = new PDO("sqlsrv:server = $server; database=$databaseName; driver=$driver", $uid, $pwd );

View file

@ -30,6 +30,22 @@ function printMoney($amt, $info)
}
}
function printCal($date)
{
$loc = setlocale(LC_TIME, 0);
$fmt = datefmt_create(
$loc,
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
datefmt_set_pattern($fmt, 'cccc');
echo datefmt_format($fmt, $date) . PHP_EOL;
datefmt_set_pattern($fmt, 'MMMM');
echo datefmt_format($fmt, $date) . PHP_EOL;
}
require_once('MsSetup.inc');
$setLocaleInfo = ($_SERVER['argv'][1]);
@ -96,8 +112,8 @@ if ($sep !== $info['thousands_sep']) {
$n1 = 10000.98765;
printMoney($n1, $info);
echo strftime("%A", strtotime("12/25/2020")) . PHP_EOL;
echo strftime("%B", strtotime("12/25/2020")) . PHP_EOL;
$d = new DateTime("12/25/2020", new DateTimeZone('America/Los_Angeles'));
printCal($d);
$conn = sqlsrv_connect($server, $connectionOptions);
if (!$conn) {