Explorar o código

fix date formatting ranges with postfix period characters

Adam Shaw %!s(int64=9) %!d(string=hai) anos
pai
achega
78616b211b
Modificáronse 2 ficheiros con 32 adicións e 2 borrados
  1. 18 2
      src/date-formatting.js
  2. 14 0
      tests/automated/formatRange.js

+ 18 - 2
src/date-formatting.js

@@ -122,7 +122,15 @@ 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, unzonedDate1, unzonedDate2,  chunks[rightI]);
+
+		// If current chunk is on the boundary of unique date-content, and is a special-case
+		// date-formatting postfix character, then don't consume it. Consider it unique date-content.
+		// TODO: configurable special-case characters.
+		if (rightI - 1 === leftI && chunks[rightI] === '.') {
+			break;
+		}
+
+		chunkStr = formatSimilarChunk(date1, date2, unzonedDate1, unzonedDate2, chunks[rightI]);
 		if (chunkStr === false) {
 			break;
 		}
@@ -224,7 +232,15 @@ function chunkFormatString(formatStr) {
 			chunks.push({ token: match[3] });
 		}
 		else if (match[5]) { // an unenclosed literal string
-			chunks.push(match[5]);
+
+			// separate non-whitespace spans from whitespace spans.
+			// TODO: generalize whitespace-splitting instead of hardcoding for one scenario.
+			if (match[5] === '. ') {
+				chunks.push('.', ' ');
+			}
+			else {
+				chunks.push(match[5]);
+			}
 		}
 	}
 

+ 14 - 0
tests/automated/formatRange.js

@@ -31,6 +31,20 @@ describe('formatRange', function() {
 		expect(s).toEqual('January 1st 2014 6:00am - 6:30am');
 	});
 
+	it('doesn\'t split a period (German)', function() {
+		var date1 = moment('2014-08-11').locale('de');
+		var date2 = moment('2014-08-17').locale('de');
+		var s = $.fullCalendar.formatRange(date1, date2, 'll');
+		expect(s).toEqual('11. - 17. Aug. 2014');
+	});
+
+	it('doesn\'t split a period (Czech)', function() {
+		var date1 = moment('2017-01-15').locale('cs');
+		var date2 = moment('2017-01-21').locale('cs');
+		var s = $.fullCalendar.formatRange(date1, date2, 'D. M. YYYY');
+		expect(s).toEqual('15. - 21. 1. 2017');
+	});
+
 	it('outputs the single date when the dates have the same day and time', function() {
 		var s = $.fullCalendar.formatRange('2014-01-01T06:00:00', '2014-01-01T06:00:00', 'MMMM Do YYYY h:mma');
 		expect(s).toEqual('January 1st 2014 6:00am');