forked from eclipse-edc/DataDashboard
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unify date formats and fix of manually editing dates (#809)
- Loading branch information
Showing
11 changed files
with
133 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {NativeDateAdapter} from '@angular/material/core'; | ||
import {isValid, parse as parseDate} from 'date-fns'; | ||
import {format as formateDate} from 'date-fns-tz'; | ||
|
||
export class CustomDateAdapter extends NativeDateAdapter { | ||
parse(value: any): Date | null { | ||
if (typeof value === 'string' && value.indexOf('/') > -1) { | ||
const parsedDate = parseDate(value, 'dd/MM/yyyy', new Date()); | ||
return isValid(parsedDate) ? parsedDate : null; | ||
} | ||
|
||
const timestamp = typeof value === 'number' ? value : Date.parse(value); | ||
return isNaN(timestamp) ? null : new Date(timestamp); | ||
} | ||
|
||
format(date: Date, displayFormat: Object): string { | ||
return formateDate(date, 'dd/MM/yyyy', { | ||
timeZone: 'UTC', | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import {CommonModule} from '@angular/common'; | ||
import {NgModule} from '@angular/core'; | ||
import {MatButtonModule} from '@angular/material/button'; | ||
import {MatCardModule} from '@angular/material/card'; | ||
import {MatChipsModule} from '@angular/material/chips'; | ||
import { | ||
DateAdapter, | ||
MAT_DATE_LOCALE, | ||
MatNativeDateModule, | ||
} from '@angular/material/core'; | ||
import {MatDatepickerModule} from '@angular/material/datepicker'; | ||
import {MatDialogModule} from '@angular/material/dialog'; | ||
import {MatDividerModule} from '@angular/material/divider'; | ||
import { | ||
MAT_FORM_FIELD_DEFAULT_OPTIONS, | ||
MatFormFieldDefaultOptions, | ||
MatFormFieldModule, | ||
} from '@angular/material/form-field'; | ||
import {MatIconModule} from '@angular/material/icon'; | ||
import {MatInputModule} from '@angular/material/input'; | ||
import {MatListModule} from '@angular/material/list'; | ||
import {MatMenuModule} from '@angular/material/menu'; | ||
import {MatSelectModule} from '@angular/material/select'; | ||
import {MatSidenavModule} from '@angular/material/sidenav'; | ||
import {MatSnackBarModule} from '@angular/material/snack-bar'; | ||
import {MatToolbarModule} from '@angular/material/toolbar'; | ||
import { | ||
MAT_TOOLTIP_DEFAULT_OPTIONS, | ||
MAT_TOOLTIP_DEFAULT_OPTIONS_FACTORY, | ||
MatTooltipDefaultOptions, | ||
MatTooltipModule, | ||
} from '@angular/material/tooltip'; | ||
import {CustomDateAdapter} from './core/adapters/custom-date-adapter'; | ||
|
||
const MODULES = [ | ||
MatButtonModule, | ||
MatCardModule, | ||
MatChipsModule, | ||
MatDatepickerModule, | ||
MatDialogModule, | ||
MatDividerModule, | ||
MatFormFieldModule, | ||
MatIconModule, | ||
MatInputModule, | ||
MatListModule, | ||
MatMenuModule, | ||
MatNativeDateModule, | ||
MatSelectModule, | ||
MatSidenavModule, | ||
MatSnackBarModule, | ||
MatToolbarModule, | ||
MatTooltipModule, | ||
]; | ||
|
||
const COMPONENTS: NgModule['declarations'] = []; | ||
|
||
@NgModule({ | ||
imports: [ | ||
// Angular | ||
CommonModule, | ||
|
||
// Angular Material | ||
...MODULES, | ||
], | ||
exports: [...MODULES, ...COMPONENTS], | ||
declarations: COMPONENTS, | ||
providers: [ | ||
{provide: DateAdapter, useClass: CustomDateAdapter}, | ||
|
||
{provide: MAT_DATE_LOCALE, useValue: 'en-GB'}, | ||
{ | ||
provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, | ||
useValue: { | ||
appearance: 'outline', | ||
color: 'accent', | ||
} as MatFormFieldDefaultOptions, | ||
}, | ||
{ | ||
provide: MAT_TOOLTIP_DEFAULT_OPTIONS, | ||
useValue: <MatTooltipDefaultOptions>{ | ||
...MAT_TOOLTIP_DEFAULT_OPTIONS_FACTORY(), | ||
disableTooltipInteractivity: true, | ||
}, | ||
}, | ||
], | ||
}) | ||
export class SharedModule {} |