Skip to content

[5.5] 'date_format:Y-m-d\TH:i:s.u\Z' fails validation but works for all intended purposes #22722

@dewwwald

Description

@dewwwald

Laravel Version: 5.5
PHP Version: 7.2.0-2+ubuntu16.04.1+deb.sury.org+2
Database Driver & Version: -

Description:

When I create a ISO String in javascript for the backend, the only possible way I found to match the format was to use 'Y-m-d\TH:i:s.u\Z'. According to the PHP documentation since version 7.0 you can supplement u with v and get the exact results that Javascript is producing. Using u actually add 000 to the milliseconds to make microseconds. I tried everything I can to use the v but it does not want to work for my php 7.2 installation (might be an issue with php 7.2).

Never the less, PHP does not mind the small difference and neither does JS. What I mean to say is that I can use u and consume JS ISO format and JS can consume the extra 000.

The problem is not one that many people will encounter (I just like the precision). However this might be a requirement for some applications.

The way I see it there is one of two options:

  1. Slack the constraints to disregard milliseconds if there was none and there is now 000.
  2. I need to relinquish storing time at a millisecond precision level in my application. (I am told to sove off)

Steps To Reproduce:

Make sure to use PHP 7.2 (not sure about rest)

Post a javascript (new Date()).toISOString() to an api.
Validate that string using any PHP date string. It seems insurmountable. Example:

[
    ...
    // does not work
    'deadline' => 'date_format:Y-m-d\TH:i:s.u\Z', 
    // should work but does not work
    'starting_date' => 'date_format:Y-m-d\TH:i:s.v\Z', 
    ...
]

I am happy to handle this edge case in my App or write code for handling the problem for the framework. That is if I will be allowed to do so and can get a few +1's to confirm.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions