php / php/doc-en

Intl MessageFormatter using incorrect timezone

Open
#1,445 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Extension: intl
Dominant language
XML
Stars
596
Forks
890
Avg merge
1d 15h
Merged PRs (30d)
55

Description

Description

The following code:

<?php
\Locale::setDefault('en-CA');
date_default_timezone_set('America/Edmonton');

$now = new \DateTime();

echo "DateFormatter - [" . \IntlDateFormatter::formatObject($now, [\IntlDateFormatter::FULL, \IntlDateFormatter::FULL]) . "]\n";

echo "Singular - [" . \MessageFormatter::formatMessage(
  \Locale::getDefault(),
  '{0, date, full} - {0, time, full}',
  [$now]
) . "]\n";

echo "Plural - [" . \MessageFormatter::formatMessage(
  \Locale::getDefault(),
  '{0, plural, 
        =0    {{1, date, full} - {1, time, full}.}
        other {{1, date, full} - {1, time, full}}
   }',
  [1, $now]
) . "]\n";
?>

Resulted in this output:
DateFormatter - [Friday, March 4, 2022 at 1:28:49 p.m. Mountain Standard Time]
Singular - [Friday, March 4, 2022 - 1:28:49 p.m. Mountain Standard Time]
Plural - [Friday, March 4, 2022 - 8:28:49 p.m. Coordinated Universal Time]

But I expected this output instead:
Plural ICU format to MessageFormatter should return the same as that shown by Singular but it seems to be ignoring the default timezone set using date_default_timezone_set() and defaulting to server timezone of UTC when using the Plural form of ICU.

PHP Version

PHP 8.1.3

Operating System

Ubuntu 18.04.6 LTS

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No documentation file or test is named. Start by reproducing the supplied PHP 8.1.3 example, comparing IntlDateFormatter, singular MessageFormatter, and plural MessageFormatter output after date_default_timezone_set('America/Edmonton'); done means establishing whether the behavior needs documentation or should be reported to the PHP implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation, internationalization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.