2
0
Эх сурвалжийг харах

optimize ISO8601 fix. do it for format() too

Adam Shaw 8 жил өмнө
parent
commit
2fd61a7306

+ 15 - 4
src/moment-ext.js

@@ -300,21 +300,32 @@ newMomentProto.format = function() {
 	if (this._fullCalendar && arguments[0]) { // an enhanced moment? and a format string provided?
 		return formatDate(this, arguments[0]); // our extended formatting
 	}
+
 	if (this._ambigTime) {
-		return oldMomentFormat(this, 'YYYY-MM-DD');
+		return oldMomentFormat(englishMoment(this), 'YYYY-MM-DD');
 	}
 	if (this._ambigZone) {
-		return oldMomentFormat(this, 'YYYY-MM-DD[T]HH:mm:ss');
+		return oldMomentFormat(englishMoment(this), 'YYYY-MM-DD[T]HH:mm:ss');
 	}
+
 	return oldMomentProto.format.apply(this, arguments);
 };
 
 newMomentProto.toISOString = function() {
+
 	if (this._ambigTime) {
-		return oldMomentFormat(moment(this).locale('en'), 'YYYY-MM-DD');
+		return oldMomentFormat(englishMoment(this), 'YYYY-MM-DD');
 	}
 	if (this._ambigZone) {
-		return oldMomentFormat(moment(this).locale('en'), 'YYYY-MM-DD[T]HH:mm:ss');
+		return oldMomentFormat(englishMoment(this), 'YYYY-MM-DD[T]HH:mm:ss');
 	}
+
 	return oldMomentProto.toISOString.apply(this, arguments);
 };
+
+function englishMoment(mom) {
+	if (mom.locale() !== 'en') {
+		return mom.clone().locale('en');
+	}
+	return mom;
+}

+ 5 - 0
tests/automated/moment-ambig.js

@@ -31,6 +31,11 @@ describe('ambiguously-zoned moment', function() {
 		expect(mom.toISOString()).toBe('2014-06-08T10:00:00');
 	});
 
+	it('formats ISO8601 via format() for locales with non-trivial formatting', function() {
+		var mom = $.fullCalendar.moment.parseZone('2014-06-08T10:00:00').locale('ar');
+		expect(mom.format()).toBe('2014-06-08T10:00:00');
+	});
+
 	it('is correctly cloned', function() {
 		var mom = $.fullCalendar.moment.parseZone('2014-06-08T10:00:00');
 		var clone = mom.clone();