config._d = date;
}
+ function dateFromObject(config) {
+ var o = config._i;
+
+ if (config._d) {
+ return;
+ }
+
+ config._a = [
+ o.years || o.year || o.y,
+ o.months || o.month || o.m,
+ o.days || o.day || o.d,
+ o.hours || o.hour || o.h,
+ o.minutes || o.minute || o.m,
+ o.seconds || o.second || o.s,
+ o.milliseconds || o.millisecond || o.ms
+ ];
+
+ dateFromArray(config);
+ }
+
function currentDateArray(config) {
var now = new Date();
if (config._useUTC) {
} else if (isArray(input)) {
config._a = input.slice(0);
dateFromArray(config);
+ } else if (input instanceof Date) {
+ config._d = new Date(+input);
+ } else if (typeof(input) == 'object') {
+ dateFromObject(config);
} else {
- config._d = input instanceof Date ? new Date(+input) : new Date(input);
+ config._d = new Date(input);
}
}
test.done();
},
+ "object" : function (test) {
+ test.expect(8);
+ test.ok(moment({year: 2010}).toDate() instanceof Date, "{year: 2010}");
+ test.ok(moment({year: 2010, month: 1}).toDate() instanceof Date, "{year: 2010, month: 1}");
+ test.ok(moment({year: 2010, month: 1, day: 12}).toDate() instanceof Date, "{year: 2010, month: 1, day: 12}");
+ test.ok(moment({year: 2010, month: 1, day: 12, hours: 1}).toDate() instanceof Date, "{year: 2010, month: 1, day: 12, hours: 1}");
+ test.ok(moment({year: 2010, month: 1, day: 12, hours: 1, minutes: 1}).toDate() instanceof Date, "{year: 2010, month: 1, hours: 12, minutes: 1, seconds: 1}");
+ test.ok(moment({year: 2010, month: 1, day: 12, hours: 1, minutes: 1, seconds: 1}).toDate() instanceof Date, "{year: 2010, month: 1, day: 12, hours: 1, minutes: 1, seconds: 1]");
+ test.ok(moment({year: 2010, month: 1, day: 12, hours: 1, minutes: 1, seconds: 1, milliseconds: 1}).toDate() instanceof Date, "{year: 2010, month: 1, day: 12, hours: 1, minutes: 1, seconds: 1, milliseconds: 1]");
+ test.equal(+moment(new Date(2010, 1, 14, 15, 25, 50, 125)), +moment({year: 2010, month: 1, day: 14, hours: 15, minutes: 25, seconds: 50, milliseconds: 125}), "constructing with object === constructing with new Date()");
+ test.done();
+ },
+
"multi format array copying": function (test) {
var importantArray = ['MM/DD/YYYY', 'YYYY-MM-DD', 'MM-DD-YYYY'];
test.expect(1);