Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { NativeDateAdapter, DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE } from "@angular/material";
export class AppDateAdapter extends NativeDateAdapter {
parse(value: any): Date | null {
if ((typeof value === 'string') && (value.indexOf('/') > -1)) {
const str = value.split('/');
const year = Number(str[2]);
const month = Number(str[1]) - 1;
const date = Number(str[0]);
return new Date(year, month, date);
}
const timestamp = typeof value === 'number' ? value : Date.parse(value);
return isNaN(timestamp) ? null : new Date(timestamp);
}
format(date: Date, displayFormat: Object): string {
if (displayFormat == "input") {
let day = date.getDate();
let month = date.getMonth() + 1;
let year = date.getFullYear();
return this._to2digit(day) + '/' + this._to2digit(month) + '/' + year;
} else {
return date.toDateString();
}
}
private _to2digit(n: number) {
return ('00' + n).slice(-2);
}
}
export const APP_DATE_FORMATS =
{
parse: {
dateInput: { month: 'short', year: 'numeric', day: 'numeric' }
},
display: {
// dateInput: { month: 'short', year: 'numeric', day: 'numeric' },
dateInput: 'input',
monthYearLabel: { month: 'short', year: 'numeric', day: 'numeric' },
dateA11yLabel: { year: 'numeric', month: 'long', day: 'numeric' },
monthYearA11yLabel: { year: 'numeric', month: 'long' },
}
MatSelectModule,
MatCheckboxModule,
MatSlideToggleModule,
MatInputModule,
MatTooltipModule,
MatTabsModule,
MatSidenavModule,
MatButtonModule,
MatCardModule,
MatButtonToggleModule,
MatProgressSpinnerModule,
MatToolbarModule,
MatMenuModule,
MatGridListModule,
MatTableModule,
MatPaginatorModule,
MatSortModule,
MatPaginatorIntl,
MatDatepickerModule,
MatNativeDateModule,
MatExpansionModule,
MatAutocompleteModule,
MatSnackBar,
MatSnackBarModule,
MatIcon,
MatIconModule,
MatDialogActions,
MatListModule,
MatChipsModule,
MatStepperModule,
import { CdkTableModule } from '@angular/cdk/table';
import { getFrenchPaginatorIntl } from './french-paginator-intl';
MatCheckboxModule,
MatSelectModule,
MatSlideToggleModule,
MatInputModule,
MatTooltipModule,
MatTabsModule,
MatSidenavModule,
MatButtonModule,
MatCardModule,
MatButtonToggleModule,
MatProgressSpinnerModule,
MatToolbarModule,
MatMenuModule,
MatGridListModule,
MatTableModule,
MatPaginatorModule,
MatSortModule,
MatDatepickerModule,
MatNativeDateModule,
MatExpansionModule,
MatAutocompleteModule,
MatSnackBarModule,
MatIconModule,
MatListModule,
MatChipsModule,
MatStepperModule,
MatSliderModule,
DndModule.forRoot()
MatCheckboxModule,
MatSelectModule,
MatSlideToggleModule,
MatInputModule,
MatTooltipModule,
MatTabsModule,
MatSidenavModule,
MatButtonModule,
MatCardModule,
MatButtonToggleModule,
MatProgressSpinnerModule,
MatToolbarModule,
MatMenuModule,
MatGridListModule,
MatTableModule,
MatPaginatorModule,
MatSortModule,
MatDatepickerModule,
MatNativeDateModule,
MatExpansionModule,
MatAutocompleteModule,
MatSnackBarModule,
MatIconModule,
MatListModule,
MatChipsModule,
MatStepperModule,
],
providers: [
{ provide: MatPaginatorIntl, useValue: getFrenchPaginatorIntl() },
{ provide: DateAdapter, useClass: AppDateAdapter },
{ provide: MAT_DATE_FORMATS, useValue: APP_DATE_FORMATS },
{ provide: MAT_DATE_LOCALE, useValue: 'fr-FR' },