|
|
@@ -98,6 +98,8 @@ FC.formatRange = formatRange; // expose
|
|
|
|
|
|
|
|
|
function formatRangeWithChunks(date1, date2, chunks, separator, isRTL) {
|
|
|
+ var unzonedDate1 = date1.clone().stripZone(); // for formatSimilarChunk
|
|
|
+ var unzonedDate2 = date2.clone().stripZone(); // "
|
|
|
var chunkStr; // the rendering of the chunk
|
|
|
var leftI;
|
|
|
var leftStr = '';
|
|
|
@@ -111,7 +113,7 @@ function formatRangeWithChunks(date1, date2, chunks, separator, isRTL) {
|
|
|
// Start at the leftmost side of the formatting string and continue until you hit a token
|
|
|
// that is not the same between dates.
|
|
|
for (leftI=0; leftI<chunks.length; leftI++) {
|
|
|
- chunkStr = formatSimilarChunk(date1, date2, chunks[leftI]);
|
|
|
+ chunkStr = formatSimilarChunk(date1, date2, unzonedDate1, unzonedDate2, chunks[leftI]);
|
|
|
if (chunkStr === false) {
|
|
|
break;
|
|
|
}
|
|
|
@@ -120,7 +122,7 @@ function formatRangeWithChunks(date1, date2, chunks, separator, isRTL) {
|
|
|
|
|
|
// Similarly, start at the rightmost side of the formatting string and move left
|
|
|
for (rightI=chunks.length-1; rightI>leftI; rightI--) {
|
|
|
- chunkStr = formatSimilarChunk(date1, date2, chunks[rightI]);
|
|
|
+ chunkStr = formatSimilarChunk(date1, date2, unzonedDate1, unzonedDate2, chunks[rightI]);
|
|
|
if (chunkStr === false) {
|
|
|
break;
|
|
|
}
|
|
|
@@ -167,7 +169,7 @@ var similarUnitMap = {
|
|
|
|
|
|
// Given a formatting chunk, and given that both dates are similar in the regard the
|
|
|
// formatting chunk is concerned, format date1 against `chunk`. Otherwise, return `false`.
|
|
|
-function formatSimilarChunk(date1, date2, chunk) {
|
|
|
+function formatSimilarChunk(date1, date2, unzonedDate1, unzonedDate2, chunk) {
|
|
|
var token;
|
|
|
var unit;
|
|
|
|
|
|
@@ -176,8 +178,10 @@ function formatSimilarChunk(date1, date2, chunk) {
|
|
|
}
|
|
|
else if ((token = chunk.token)) {
|
|
|
unit = similarUnitMap[token.charAt(0)];
|
|
|
+
|
|
|
// are the dates the same for this unit of measurement?
|
|
|
- if (unit && date1.isSame(date2, unit)) {
|
|
|
+ // use the unzoned dates for this calculation because unreliable when near DST (bug #2396)
|
|
|
+ if (unit && unzonedDate1.isSame(unzonedDate2, unit)) {
|
|
|
return oldMomentFormat(date1, token); // would be the same if we used `date2`
|
|
|
// BTW, don't support custom tokens
|
|
|
}
|