[GH #7681] correctFormat not correctly inferring DD/MM inputs

Tags: #<Tag:0x00007f8b1ddcc7b0> #<Tag:0x00007f8b1ddcc648>

correctFormat seems to have a few problems inferring date from incomplete inputs.

This is how the date column is set up: (React)

      correctFormat={true}
      columns={[
        {
          data: 'date',
          type: 'date',
          dateFormat: 'DD/MM/YYYY',
        }
       ...

The expected behaviour is that any input of the type D/M e.g. 15/2 should be converted to DD/MM/YYYY for the current year.

I think the problem is best described by a series of examples of what does/doesn’t work:

// input => result

// if both DD < 13 && MM < 13, it works
1/2/21 => 01/02/2021 // works
1/2 => 01/02/2021 // works
1/2/2021 => 01/02/2021 // works

15/2/21 => 15/2/21 // doesn't work, red warning, expected 15/02/2021
15/2 => 15/2 // doesn't work, red warning, expected 15/02/2021

2/15/21 => 15/02/2021 // works, but irrelevant for my usecase
02/15/2021 => 15/02/2021 // works, but irrelevant for my usecase
2/15 => 15/02/2001 // doesn't work, but irrelevant for my usecase

// typing out the full year also has mixed results
2/15/2021 => 15/02/2021 // works, but irrelevant for my usecase
15/2/2021 => 15/2/2021 // doesn't work, expected 15/02/2021
1/2/2021 => 01/02/2021 // works

// finally, typing the date verbatim works
15/02/2021 => 15/02/2021 // works

In other words, it seems like the parser always interpret the inputs as M/D. From the short time I worked with moment I know this is a tough one to solve, but at the very least correctFormat should consider what dateFormat I’ve set. E.g. It should be able to read dateFormat: DD/MM/YYYY and infer that I’m expected to input DD/MM or D/M or D/M/YY etc.

Thank you for sharing those cases @dalmo

I think that as long as [‘1/2’] is correct the [‘15/2/2021’] also should be correct. I will investigate the topic further and update you after the weekend.

Hi @dalmo

I’ve discussed the issue with the team and they all agreed that this is a bug. I have simplified the example here https://github.com/handsontable/handsontable/issues/7681 but if you think that I’ve missed any pattern other than what is already mentioned please feel free to add a comment.

1 Like