Skip to content

fromISO too loose / fromFormat restrictive #1628

@angelaki

Description

@angelaki

I'm just wondering why fromISO accepts pretty much every input while fromFormat need to match 100%:

//Why is this getting parsed?
const iso = DateTime.fromISO('11');
console.log(iso.toISO());
console.log(iso.isValid);

//Why is this *not* getting parsed?!
const input = DateTime.fromFormat('11', 'D');
console.log(input.toISO());
console.log(input.isValid);

(https://stackblitz.com/edit/vitejs-vite-3v4qvn)

I'm asking because (using Angular) I switched to Luxon and their implementation of the Luxon DateAdapter feels pretty broken: https://github.com/angular/components/blob/main/src/material-luxon-adapter/adapter/luxon-date-adapter.ts

But in the end it goes down to that question: why is fromISO so loose / fromFormat so restrictive? Is there an equivalent to old moments' strict: false? To would I need to loop over several input formats (from strict to loose) until the first one matches?

date-fns solved it quite handy: a default date can be passed to fill the missing positions.

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