Skip to content

Commit a81dc00

Browse files
authored
Merge pull request jonaswinkler#1370 from paperless-ngx/fix/date-pasting
Fix: correct date pasting with some non-US formats
2 parents 765fea7 + a0f4813 commit a81dc00

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src-ui/src/app/components/common/input/date/date.component.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { Component, forwardRef, OnInit } from '@angular/core'
22
import { NG_VALUE_ACCESSOR } from '@angular/forms'
3-
import { NgbDateParserFormatter } from '@ng-bootstrap/ng-bootstrap'
3+
import {
4+
NgbDateAdapter,
5+
NgbDateParserFormatter,
6+
} from '@ng-bootstrap/ng-bootstrap'
47
import { SettingsService } from 'src/app/services/settings.service'
5-
import { LocalizedDateParserFormatter } from 'src/app/utils/ngb-date-parser-formatter'
68
import { AbstractInputComponent } from '../abstract-input'
79

810
@Component({
@@ -23,7 +25,8 @@ export class DateComponent
2325
{
2426
constructor(
2527
private settings: SettingsService,
26-
private ngbDateParserFormatter: NgbDateParserFormatter
28+
private ngbDateParserFormatter: NgbDateParserFormatter,
29+
private isoDateAdapter: NgbDateAdapter<string>
2730
) {
2831
super()
2932
}
@@ -43,9 +46,10 @@ export class DateComponent
4346
let pastedText = clipboardData.getData('text')
4447
pastedText = pastedText.replace(/[\sa-z#!$%\^&\*;:{}=\-_`~()]+/g, '')
4548
const parsedDate = this.ngbDateParserFormatter.parse(pastedText)
46-
const formattedDate = this.ngbDateParserFormatter.format(parsedDate)
47-
this.writeValue(formattedDate)
48-
this.onChange(formattedDate)
49+
if (parsedDate) {
50+
this.writeValue(this.isoDateAdapter.toModel(parsedDate))
51+
this.onChange(this.value)
52+
}
4953
}
5054
}
5155

0 commit comments

Comments
 (0)