Merge pull request #864 from paperless-ngx/fix-863

Always accept yyyy-mm-dd date inputs
This commit is contained in:
Quinn Casey 2022-05-02 08:10:49 -07:00 committed by GitHub
commit 9d9111e4d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -51,11 +51,22 @@ export class LocalizedDateParserFormatter extends NgbDateParserFormatter {
const dateSeparator = inputFormat.replace(/[dmy]/gi, '').charAt(0)
if (this.separatorRegExp.test(value)) {
// split on separator, pad & re-join without separator
value = value
.split(this.separatorRegExp)
.map((segment) => segment.padStart(2, '0'))
.join('')
let segments = value.split(this.separatorRegExp)
// always accept strict yyyy*mm*dd format even if thats not the input format since we can be certain its not yyyy*dd*mm
if (
value.length == 10 &&
segments.length == 3 &&
segments[0].length == 4
) {
return inputFormat
.replace('yyyy', segments[0])
.replace('mm', segments[1])
.replace('dd', segments[2])
} else {
// otherwise pad & re-join without separator
value = segments.map((segment) => segment.padStart(2, '0')).join('')
}
}
if (value.length == 4 && inputFormat.substring(0, 4) != 'yyyy') {