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 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!