Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 562e41a

Browse files
committed
fix(datepicker): handle DST incocnsistency encountered in some timezones. Fixes #4215.
1 parent 85dceef commit 562e41a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/components/datepicker/dateLocaleProvider.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,23 @@
154154
* @returns {string}
155155
*/
156156
function defaultFormatDate(date) {
157-
return date ? date.toLocaleDateString() : '';
157+
if (!date) {
158+
return '';
159+
}
160+
161+
// All of the dates created through ng-material *should* be set to midnight.
162+
// If we encounter a date where the localeTime shows at 11pm instead of midnight,
163+
// we have run into an issue with DST where we need to increment the hour by one:
164+
// var d = new Date(1992, 9, 8, 0, 0, 0);
165+
// d.toLocaleString(); // == "10/7/1992, 11:00:00 PM"
166+
var localeTime = date.toLocaleTimeString();
167+
var formatDate = date;
168+
if (date.getHours() == 0 &&
169+
(localeTime.indexOf('11:') !== -1 || localeTime.indexOf('23:') !== -1)) {
170+
formatDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 1, 0, 0);
171+
}
172+
173+
return formatDate.toLocaleDateString();
158174
}
159175

160176
/**

0 commit comments

Comments
 (0)