Skip to content

Date parse: lenient about zero-padding date fields #695

@rxaviers

Description

@rxaviers

Date parser is strict about parsing zero-padded date fields, for example parsing yMd skeleton for pt (that means pattern dd/MM/y), we have:

Globalize('pt').parseDate('23/02/2017');
// > 2017-02-23T03:00:00.000Z

Globalize('pt').parseDate('23/2/2017');
// > null

Though it's impossible to set parser to parse non-zero-padded day and month for pt unless it's used raw to pass the pattern itself (which is not recommended). Therefore, parser should be lenient about parsing those date fields, specially the ones below for the analogous reason.

  • year: date: "short" may include y or yy, also y isn't the non-zero-padded for yy, what makes it even more mandatory to have a way to parse non-zero-added yy.
  • month: skeleton: "yMd" (i.e., one M) may include MM as the pattern); similarly L.
  • day: skeleton: "yMd" (i.e., one d) may include d or dd
  • hour: skeleton: "hms" (i.e., one h) may include h or hh; similarly HKk.
  • minute: skeleton: "hms" (i.e., one m) always includes mm
  • second: skeleton: "hms" (i.e., one s) always includes ss

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions