duannian4784 2018-10-25 10:39
浏览 44

Symfony / PHP DateTimeZone缺少时区

I've got a Symfony API that is storing the users timezone as part of the login process. However, it seems certain timezones causes an error. Using 'America/Buenos_Aires' as an example value being sent, the following code causes 500 error to be thrown.

$validator->validate($request->request, new Assert\Collection([
        'username' => new AppAssert\Chain([
            new Assert\Type('string'),
            new Assert\NotBlank(),
        ]),
        'password' => new AppAssert\Chain([
            new Assert\Type('string'),
            new Assert\NotBlank(),
        ]),
        'timezone' => new AppAssert\Chain([
            new Assert\Type('string'),
            new Assert\NotIdenticalTo(''),
            new Assert\Choice([
                'choices' => \DateTimeZone::listIdentifiers(),
                'strict' => true,
            ]),
        ]),
    ]));

Looking at this post https://bugs.php.net/bug.php?id=70816 it states to use DateTimeZone::ALL_WITH_BC, which I've tried

'choices' => \DateTimeZone::listIdentifiers(DateTimeZone::ALL_WITH_BC),

but still to no avial.

The client is using Moment JS which seems to sometimes return America/Argentina/Buenos_Aires and sometimes America/Buenos_Aires but America/Argentina/Buenos_Aires works fine.

  • 写回答

1条回答 默认 最新

  • doushu5805 2018-10-25 14:42
    关注

    I finally figured it out, I was missing \ off DateTimeZone::ALL_WITH_BC

    Full correct code

     'timezone' => new AppAssert\Chain([
                new Assert\Type('string'),
                new Assert\NotIdenticalTo(''),
                new Assert\Choice([
                    'choices' => \DateTimeZone::listIdentifiers(\DateTimeZone::ALL_WITH_BC),
                    'strict' => true,
                ]),
            ]),
    
    评论

报告相同问题?

悬赏问题

  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了