Skip to content

Commit

Permalink
fix(datepicker): correct DST issues on IE 11
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba committed Oct 17, 2017
1 parent 26bbeb2 commit 1ef6400
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/lib/core/datetime/native-date-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import {Inject, Injectable, Optional} from '@angular/core';
import {DateAdapter, MAT_DATE_LOCALE} from './date-adapter';
import {extendObject} from '../util/object-extend';
import {Platform} from '@angular/cdk/platform';

// TODO(mmalerba): Remove when we no longer support safari 9.
/** Whether the browser supports the Intl API. */
Expand Down Expand Up @@ -59,18 +60,21 @@ function range<T>(length: number, valueFunction: (index: number) => T): T[] {
/** Adapts the native JS Date for use with cdk-based components that work with dates. */
@Injectable()
export class NativeDateAdapter extends DateAdapter<Date> {
constructor(@Optional() @Inject(MAT_DATE_LOCALE) matDateLocale: string) {
super();
super.setLocale(matDateLocale);
}

/**
* Whether to use `timeZone: 'utc'` with `Intl.DateTimeFormat` when formatting dates.
* Without this `Intl.DateTimeFormat` sometimes chooses the wrong timeZone, which can throw off
* the result. (e.g. in the en-US locale `new Date(1800, 7, 14).toLocaleDateString()`
* will produce `'8/13/1800'`.
*/
useUtcForDisplay = true;
useUtcForDisplay: boolean;

constructor(@Optional() @Inject(MAT_DATE_LOCALE) matDateLocale: string, platform: Platform) {
super();
super.setLocale(matDateLocale);

// IE does its own time zone correction, so we disable this on IE.
this.useUtcForDisplay = !platform.TRIDENT;
}

getYear(date: Date): number {
return date.getFullYear();
Expand Down

0 comments on commit 1ef6400

Please sign in to comment.