Skip to content

Commit 1ef6400

Browse files
committed
fix(datepicker): correct DST issues on IE 11
1 parent 26bbeb2 commit 1ef6400

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import {Inject, Injectable, Optional} from '@angular/core';
1010
import {DateAdapter, MAT_DATE_LOCALE} from './date-adapter';
1111
import {extendObject} from '../util/object-extend';
12+
import {Platform} from '@angular/cdk/platform';
1213

1314
// TODO(mmalerba): Remove when we no longer support safari 9.
1415
/** Whether the browser supports the Intl API. */
@@ -59,18 +60,21 @@ function range<T>(length: number, valueFunction: (index: number) => T): T[] {
5960
/** Adapts the native JS Date for use with cdk-based components that work with dates. */
6061
@Injectable()
6162
export class NativeDateAdapter extends DateAdapter<Date> {
62-
constructor(@Optional() @Inject(MAT_DATE_LOCALE) matDateLocale: string) {
63-
super();
64-
super.setLocale(matDateLocale);
65-
}
66-
6763
/**
6864
* Whether to use `timeZone: 'utc'` with `Intl.DateTimeFormat` when formatting dates.
6965
* Without this `Intl.DateTimeFormat` sometimes chooses the wrong timeZone, which can throw off
7066
* the result. (e.g. in the en-US locale `new Date(1800, 7, 14).toLocaleDateString()`
7167
* will produce `'8/13/1800'`.
7268
*/
73-
useUtcForDisplay = true;
69+
useUtcForDisplay: boolean;
70+
71+
constructor(@Optional() @Inject(MAT_DATE_LOCALE) matDateLocale: string, platform: Platform) {
72+
super();
73+
super.setLocale(matDateLocale);
74+
75+
// IE does its own time zone correction, so we disable this on IE.
76+
this.useUtcForDisplay = !platform.TRIDENT;
77+
}
7478

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

0 commit comments

Comments
 (0)