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

Commit

Permalink
fix(datepicker): handle DST incocnsistency encountered in some timezo…
Browse files Browse the repository at this point in the history
…nes. Fixes #4215.
  • Loading branch information
jelbourn committed Sep 10, 2015
1 parent 85dceef commit 562e41a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/components/datepicker/dateLocaleProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,23 @@
* @returns {string}
*/
function defaultFormatDate(date) {
return date ? date.toLocaleDateString() : '';
if (!date) {
return '';
}

// All of the dates created through ng-material *should* be set to midnight.
// If we encounter a date where the localeTime shows at 11pm instead of midnight,
// we have run into an issue with DST where we need to increment the hour by one:
// var d = new Date(1992, 9, 8, 0, 0, 0);
// d.toLocaleString(); // == "10/7/1992, 11:00:00 PM"
var localeTime = date.toLocaleTimeString();
var formatDate = date;
if (date.getHours() == 0 &&
(localeTime.indexOf('11:') !== -1 || localeTime.indexOf('23:') !== -1)) {
formatDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 1, 0, 0);
}

return formatDate.toLocaleDateString();
}

/**
Expand Down

0 comments on commit 562e41a

Please sign in to comment.