Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/lib/core/datetime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -19,6 +20,7 @@ export * from './native-date-formats';


@NgModule({
imports: [PlatformModule],
providers: [
{provide: DateAdapter, useClass: NativeDateAdapter},
MAT_DATE_LOCALE_PROVIDER
Expand Down
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 @@ -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';
Expand Down Expand Up @@ -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;
Copy link
Member

@crisbeto crisbeto Oct 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Can this be feature-detected (e.g. creating a date and verifying that the time is correct)?
  2. Is it IE-exclusive or does it happen on Edge as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Not really, it depends on the locale the user is in and when / if they have DST
  2. IE only

I also intentionally left this public so it can be overridden by users as an easy fix while I investigate any future bugs related to this

}

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