Merge pull request #4758 from abpframework/refactor/4757

Changed NgbDatepicker date format
pull/4777/head
Levent Arman Özak 5 years ago committed by GitHub
commit 449eb431aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,8 @@
import { ApplicationConfiguration, ConfigState } from '@abp/ng.core';
import { DatePipe } from '@angular/common';
import { Injectable, Optional } from '@angular/core';
import { NgbDateParserFormatter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap';
import { DatePipe } from '@angular/common';
import { Store } from '@ngxs/store';
function padNumber(value: number) {
if (isNumber(value)) {
@ -20,7 +22,7 @@ function toInteger(value: any): number {
@Injectable()
export class DateParserFormatter extends NgbDateParserFormatter {
constructor(@Optional() private datePipe: DatePipe) {
constructor(@Optional() private datePipe: DatePipe, private store: Store) {
super();
}
@ -48,8 +50,15 @@ export class DateParserFormatter extends NgbDateParserFormatter {
}
format(date: NgbDateStruct): string {
const { shortDatePattern } = (this.store.selectSnapshot(
ConfigState.getOne('localization'),
) as ApplicationConfiguration.Localization).currentCulture.dateTimeFormat;
if (date && this.datePipe) {
return this.datePipe.transform(new Date(date.year, date.month - 1, date.day), 'shortDate');
return this.datePipe.transform(
new Date(date.year, date.month - 1, date.day),
shortDatePattern,
);
} else {
return date
? `${date.year}-${isNumber(date.month) ? padNumber(date.month) : ''}-${

Loading…
Cancel
Save