mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-12 01:26:47 +01:00
Allow formatting non-padded dates
This commit is contained in:
parent
a33dce1948
commit
1807811903
3 changed files with 13 additions and 2 deletions
|
|
@ -2,6 +2,7 @@ import { Component, forwardRef, Input, OnInit, ViewChild } from '@angular/core';
|
|||
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
|
||||
import { NgbDateAdapter, NgbDateParserFormatter, NgbDatepickerContent } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { SettingsService } from 'src/app/services/settings.service';
|
||||
import { LocalizedDateParserFormatter } from 'src/app/utils/ngb-date-parser-formatter';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { AbstractInputComponent } from '../abstract-input';
|
||||
|
||||
|
|
@ -29,4 +30,14 @@ export class DateComponent extends AbstractInputComponent<string> implements OnI
|
|||
|
||||
placeholder: string
|
||||
|
||||
// Allow dates to be specified without 'padding' e.g. 2/3
|
||||
onFocusOut() {
|
||||
if (!this.value || this.value.length > 8) return; // its already been formatted
|
||||
if ([',','.','/','-'].some(sep => this.value.includes(sep))) {
|
||||
let valArr = this.value.split(/[\.,\/-]+/)
|
||||
valArr = valArr.map(segment => segment.padStart(2,'0'))
|
||||
let dateFormatter = new LocalizedDateParserFormatter(this.settings)
|
||||
this.value = dateFormatter.preformatDateInput(valArr.join(''))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue