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' :
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);
}
return +this._d;
},
- 'native' : function () {
- return this._d;
++
+ unix : function () {
+ return Math.floor(+this._d / 1000);
},
toString : function () {
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();
},