Skip to content

Commit 2f2325a

Browse files
mmalerbajosephperrott
authored andcommitted
fix(datepicker): correct DST issues on IE 11 (#7858)
1 parent c088a0f commit 2f2325a

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/lib/core/datetime/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
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';
11-
import {NativeDateAdapter} from './native-date-adapter';
1212
import {MAT_DATE_FORMATS} from './date-formats';
13+
import {NativeDateAdapter} from './native-date-adapter';
1314
import {MAT_NATIVE_DATE_FORMATS} from './native-date-formats';
1415

1516
export * from './date-adapter';
@@ -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: 10 additions & 6 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 {extendObject} from '../util/object-extend';
1112
import {DateAdapter, MAT_DATE_LOCALE} from './date-adapter';
@@ -60,18 +61,21 @@ function range<T>(length: number, valueFunction: (index: number) => T): T[] {
6061
/** Adapts the native JS Date for use with cdk-based components that work with dates. */
6162
@Injectable()
6263
export class NativeDateAdapter extends DateAdapter<Date> {
63-
constructor(@Optional() @Inject(MAT_DATE_LOCALE) matDateLocale: string) {
64-
super();
65-
super.setLocale(matDateLocale);
66-
}
67-
6864
/**
6965
* Whether to use `timeZone: 'utc'` with `Intl.DateTimeFormat` when formatting dates.
7066
* Without this `Intl.DateTimeFormat` sometimes chooses the wrong timeZone, which can throw off
7167
* the result. (e.g. in the en-US locale `new Date(1800, 7, 14).toLocaleDateString()`
7268
* will produce `'8/13/1800'`.
7369
*/
74-
useUtcForDisplay = true;
70+
useUtcForDisplay: boolean;
71+
72+
constructor(@Optional() @Inject(MAT_DATE_LOCALE) matDateLocale: string, platform: Platform) {
73+
super();
74+
super.setLocale(matDateLocale);
75+
76+
// IE does its own time zone correction, so we disable this on IE.
77+
this.useUtcForDisplay = !platform.TRIDENT;
78+
}
7579

7680
getYear(date: Date): number {
7781
return date.getFullYear();

0 commit comments

Comments
 (0)