Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] intl的formatDate 函数calendar参数不生效 #12858

Closed
TivonJJ opened this issue Dec 24, 2024 · 1 comment
Closed

[Bug] intl的formatDate 函数calendar参数不生效 #12858

TivonJJ opened this issue Dec 24, 2024 · 1 comment

Comments

@TivonJJ
Copy link

TivonJJ commented Dec 24, 2024

What happens?

Intl的formatDate函数,传入参数calendar不生效,导致我的泰国时间显示不是全球通用时间,我需要传入calendar=gregory参数,
我尝试直接使用react-intl的函数是没有问题的,似乎是umi的plugin二次封装丢掉了此属性!

Mini Showcase Repository(REQUIRED)

import { getIntl } from 'umi';
import moment from 'moment';

// intl 的locale 属性是 th-TH
const intl = getIntl();
const d = moment.utc('2024-02-02 00:00:00');
const output = intl.formatDate(d.toDate(),{
                    year: 'numeric',
                    month: '2-digit',
                    day: '2-digit',
                    hour: 'numeric',
                    minute: 'numeric',
                    second: 'numeric',
                    timeZone: 'Asia/Bangkok',
                    calendar: 'gregory',
})
// 输出是  02/02/2567 08:00:00 正常结果应该是 02/02/2567 08:00:00

// 以下是我直接使用react-intl的方式输出结果正常
import { createIntl } from 'react-intl';
 const intl = createIntl({
        locale:'th-TH',
        messages: {},
 });
 const output = intl.formatDate(d.toDate(),{
                    year: 'numeric',
                    month: '2-digit',
                    day: '2-digit',
                    hour: 'numeric',
                    minute: 'numeric',
                    second: 'numeric',
                    timeZone: 'Asia/Bangkok',
                    calendar: 'gregory',
  })
// 输出结果是02/02/2567 08:00:00, calendar=gregory生效结果正常。

How To Reproduce

  1. 设置语言为泰语 th-TH
  2. 设置时区为泰国曼谷
  3. 传入日期时间,将calendar设置为gregory

补充

createIntl是否应该在umi上面暴露出来,我现在需要创建全球的时区,需要createIntl函数。
但是现在函数在 @@/plugin-locale/localeExports 临时目录内,新版本umi似乎不允许引用临时目录了。该函数很有必要暴露出来。

Context

  • Umi Version: 4.3.19
  • Node Version: 20.9.0
  • Platform: Chrome Web Browser
Copy link

由于缺乏足够的信息,我们暂时关闭了该 Issue。请修改(不要回复) Issue 提供最小重现以重新开启。谢谢。

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant