Skip to content

Commit ca37a7f

Browse files
devversionmmalerba
authored andcommitted
refactor(native-date-adapter): remove hard-coded platform IE check (#9190)
* Removes the hard-coded platform check for IE in the NativeDateAdapter.
1 parent 3aceb73 commit ca37a7f

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/lib/core/datetime/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {PlatformModule} from '@angular/cdk/platform';
910
import {NgModule} from '@angular/core';
1011
import {DateAdapter, MAT_DATE_LOCALE_PROVIDER} from './date-adapter';
1112
import {MAT_DATE_FORMATS} from './date-formats';
@@ -19,6 +20,7 @@ export * from './native-date-formats';
1920

2021

2122
@NgModule({
23+
imports: [PlatformModule],
2224
providers: [
2325
{provide: DateAdapter, useClass: NativeDateAdapter},
2426
MAT_DATE_LOCALE_PROVIDER

src/lib/core/datetime/native-date-adapter.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {Platform} from '@angular/cdk/platform';
910
import {Inject, Injectable, Optional} from '@angular/core';
1011
import {DateAdapter, MAT_DATE_LOCALE} from './date-adapter';
1112

@@ -67,20 +68,15 @@ export class NativeDateAdapter extends DateAdapter<Date> {
6768
* the result. (e.g. in the en-US locale `new Date(1800, 7, 14).toLocaleDateString()`
6869
* will produce `'8/13/1800'`.
6970
*/
70-
useUtcForDisplay: boolean;
71+
useUtcForDisplay: boolean = true;
7172

72-
constructor(@Optional() @Inject(MAT_DATE_LOCALE) matDateLocale: string) {
73+
constructor(@Optional() @Inject(MAT_DATE_LOCALE) matDateLocale: string, platform: Platform) {
7374
super();
7475
super.setLocale(matDateLocale);
7576

7677
// IE does its own time zone correction, so we disable this on IE.
77-
// TODO(mmalerba): replace with checks from PLATFORM, logic currently duplicated to avoid
78-
// breaking change from injecting the Platform.
79-
const isBrowser = typeof document === 'object' && !!document;
80-
const isIE = isBrowser && /(msie|trident)/i.test(navigator.userAgent);
81-
82-
this.useUtcForDisplay = !isIE;
83-
this._clampDate = isIE || (isBrowser && /(edge)/i.test(navigator.userAgent));
78+
this.useUtcForDisplay = !platform.TRIDENT;
79+
this._clampDate = platform.TRIDENT || platform.EDGE;
8480
}
8581

8682
getYear(date: Date): number {

0 commit comments

Comments
 (0)