fix(datepicker): correct DST issues on IE 11 (#7858)

This commit is contained in:
mmalerba
2017-11-07 09:52:39 -08:00
committed by Joey Perrott
parent c088a0f372
commit 2f2325a856
2 changed files with 13 additions and 7 deletions
+3 -1
View File
@@ -6,10 +6,11 @@
* found in the LICENSE file at https://angular.io/license
*/
import {PlatformModule} from '@angular/cdk/platform';
import {NgModule} from '@angular/core';
import {DateAdapter, MAT_DATE_LOCALE_PROVIDER} from './date-adapter';
import {NativeDateAdapter} from './native-date-adapter';
import {MAT_DATE_FORMATS} from './date-formats';
import {NativeDateAdapter} from './native-date-adapter';
import {MAT_NATIVE_DATE_FORMATS} from './native-date-formats';
export * from './date-adapter';
@@ -19,6 +20,7 @@ export * from './native-date-formats';
@NgModule({
imports: [PlatformModule],
providers: [
{provide: DateAdapter, useClass: NativeDateAdapter},
MAT_DATE_LOCALE_PROVIDER
+10 -6
View File
@@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Platform} from '@angular/cdk/platform';
import {Inject, Injectable, Optional} from '@angular/core';
import {extendObject} from '../util/object-extend';
import {DateAdapter, MAT_DATE_LOCALE} from './date-adapter';
@@ -60,18 +61,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();