From: Tim Wood Date: Thu, 26 Apr 2012 16:36:12 +0000 (-0700) Subject: Merging in version 1.6.0 X-Git-Tag: 1.6.0~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c196bb9546a997e4e81d2a1085a43b42e341f24f;p=thirdparty%2Fmoment.git Merging in version 1.6.0 --- c196bb9546a997e4e81d2a1085a43b42e341f24f diff --cc moment.js index 4e1c5c672,4cc60e0fb..9242167a6 --- a/moment.js +++ b/moment.js @@@ -188,11 -278,13 +277,7 @@@ return currentSeconds; case 'ss' : return leftZeroFill(currentSeconds, 2); - case 'S' : - return ~~ (currentMilliseconds / 100); - case 'SS' : - return leftZeroFill(~~(currentMilliseconds / 10), 2); - case 'SSS' : - return leftZeroFill(currentMilliseconds, 3); // TIMEZONE - case 'zz' : - // depreciating 'zz' fall through to 'z' - case 'z' : - return (m._d.toString().match(timezoneRegex) || [''])[0].replace(nonuppercaseLetters, ''); case 'Z' : return (currentZone < 0 ? '-' : '+') + leftZeroFill(~~(Math.abs(currentZone) / 60), 2) + ':' + leftZeroFill(~~(Math.abs(currentZone) % 60), 2); case 'ZZ' : @@@ -378,11 -520,11 +513,11 @@@ return new Date(string); } - // helper function for _date.from() and _date.fromNow() - function substituteTimeAgo(string, number, withoutSuffix) { + // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize + function substituteTimeAgo(string, number, withoutSuffix, isFuture) { var rt = moment.relativeTime[string]; return (typeof rt === 'function') ? - rt(number || 1, !!withoutSuffix, string, isFuture) : + rt(number || 1, !!withoutSuffix, string) : rt.replace(/%d/i, number || 1); } @@@ -577,8 -720,8 +717,9 @@@ return +this._d; }, - 'native' : function () { - return this._d; ++ + unix : function () { + return Math.floor(+this._d / 1000); }, toString : function () { diff --cc test/moment/create.js index 59cb748d6,88b520135..ff7487a51 --- a/test/moment/create.js +++ b/test/moment/create.js @@@ -99,16 -118,33 +105,33 @@@ exports.create = test.done(); }, + "string with format no separators" : function(test) { + moment.lang('en'); + var a = [ + ['MMDDYYYY', '12021999'], + ['DDMMYYYY', '12021999'], + ['YYYYMMDD', '19991202'] + ],i; + + test.expect(a.length); + + for (i = 0; i < a.length; i++) { + test.equal(moment(a[i][1], a[i][0]).format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); + } + + test.done(); + }, + "string with format (timezone)" : function(test) { test.expect(8); - test.equal(moment('5 -0700', 'H ZZ').toDate().getUTCHours(), 12, 'parse hours "5 -0700" ---> "H ZZ"'); - test.equal(moment('5 -07:00', 'H Z').toDate().getUTCHours(), 12, 'parse hours "5 -07:00" ---> "H Z"'); - test.equal(moment('5 -0730', 'H ZZ').toDate().getUTCMinutes(), 30, 'parse hours "5 -0730" ---> "H ZZ"'); - test.equal(moment('5 -07:30', 'H Z').toDate().getUTCMinutes(), 30, 'parse hours "5 -07:30" ---> "H Z"'); - test.equal(moment('5 +0100', 'H ZZ').toDate().getUTCHours(), 4, 'parse hours "5 +0100" ---> "H ZZ"'); - test.equal(moment('5 +01:00', 'H Z').toDate().getUTCHours(), 4, 'parse hours "5 +01:00" ---> "H Z"'); - test.equal(moment('5 +0130', 'H ZZ').toDate().getUTCMinutes(), 30, 'parse hours "5 +0130" ---> "H ZZ"'); - test.equal(moment('5 +01:30', 'H Z').toDate().getUTCMinutes(), 30, 'parse hours "5 +01:30" ---> "H Z"'); + test.equal(moment('5 -0700', 'H ZZ').native().getUTCHours(), 12, 'parse hours "5 -0700" ---> "H ZZ"'); + test.equal(moment('5 -07:00', 'H Z').native().getUTCHours(), 12, 'parse hours "5 -07:00" ---> "H Z"'); + test.equal(moment('5 -0730', 'H ZZ').native().getUTCMinutes(), 30, 'parse hours "5 -0730" ---> "H ZZ"'); + test.equal(moment('5 -07:30', 'H Z').native().getUTCMinutes(), 30, 'parse hours "5 -07:30" ---> "H Z"'); + test.equal(moment('5 +0100', 'H ZZ').native().getUTCHours(), 4, 'parse hours "5 +0100" ---> "H ZZ"'); + test.equal(moment('5 +01:00', 'H Z').native().getUTCHours(), 4, 'parse hours "5 +01:00" ---> "H Z"'); + test.equal(moment('5 +0130', 'H ZZ').native().getUTCMinutes(), 30, 'parse hours "5 +0130" ---> "H ZZ"'); + test.equal(moment('5 +01:30', 'H Z').native().getUTCMinutes(), 30, 'parse hours "5 +01:30" ---> "H Z"'); test.done(); },