|
9 | 9 | import {Inject, Injectable, Optional} from '@angular/core';
|
10 | 10 | import {DateAdapter, MAT_DATE_LOCALE} from './date-adapter';
|
11 | 11 | import {extendObject} from '../util/object-extend';
|
| 12 | +import {Platform} from '@angular/cdk/platform'; |
12 | 13 |
|
13 | 14 | // TODO(mmalerba): Remove when we no longer support safari 9.
|
14 | 15 | /** Whether the browser supports the Intl API. */
|
@@ -59,18 +60,21 @@ function range<T>(length: number, valueFunction: (index: number) => T): T[] {
|
59 | 60 | /** Adapts the native JS Date for use with cdk-based components that work with dates. */
|
60 | 61 | @Injectable()
|
61 | 62 | export class NativeDateAdapter extends DateAdapter<Date> {
|
62 |
| - constructor(@Optional() @Inject(MAT_DATE_LOCALE) matDateLocale: string) { |
63 |
| - super(); |
64 |
| - super.setLocale(matDateLocale); |
65 |
| - } |
66 |
| - |
67 | 63 | /**
|
68 | 64 | * Whether to use `timeZone: 'utc'` with `Intl.DateTimeFormat` when formatting dates.
|
69 | 65 | * Without this `Intl.DateTimeFormat` sometimes chooses the wrong timeZone, which can throw off
|
70 | 66 | * the result. (e.g. in the en-US locale `new Date(1800, 7, 14).toLocaleDateString()`
|
71 | 67 | * will produce `'8/13/1800'`.
|
72 | 68 | */
|
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 | + } |
74 | 78 |
|
75 | 79 | getYear(date: Date): number {
|
76 | 80 | return date.getFullYear();
|
|
0 commit comments