['HH:mm', /T\d\d:\d\d/],
['HH', /T\d\d/]
],
- timezoneParseRegex = /([\+\-]|\d\d)/gi,
- VERSION = "1.5.0",
- shortcuts = 'Month|Date|Hours|Minutes|Seconds|Milliseconds'.split('|'),
+
+ // timezone chunker "+10:00" > ["10", "00"] or "-1530" > ["-15", "30"]
+ parseTimezoneChunker = /([\+\-]|\d\d)/gi,
+
+ // getter and setter names
- proxyGettersAndSetters = 'Month|Date|Hours|Minutes|Seconds|Milliseconds'.split('|');
++ proxyGettersAndSetters = 'Month|Date|Hours|Minutes|Seconds|Milliseconds'.split('|'),
+ durationGetters = 'years|months|days|hours|minutes|seconds|milliseconds'.split('|'),
+ unitMillisecondFactors = {
+ 'Milliseconds' : 1,
+ 'Seconds' : 1e3,
+ 'Minutes' : 6e4,
+ 'Hours' : 36e5,
+ 'Days' : 864e5,
+ 'Weeks' : 6048e5,
+ 'Months' : 2592e6,
+ 'Years' : 31536e6
+ };
// Moment prototype object
function Moment(date, isUTC) {
return null;
}
var date,
-- matched;
++ matched,
++ isUTC;
// parse Moment object
-- if (input && input._d instanceof Date) {
++ if (moment.isMoment(input)) {
date = new Date(+input._d);
++ isUTC = input._isUTC;
// parse string and format
} else if (format) {
if (isArray(format)) {
typeof input === 'string' ? makeDateFromString(input) :
new Date(input);
}
-- return new Moment(date);
++ return new Moment(date, isUTC);
};
// creating with utc
}
// add shortcut for year (uses different syntax than the getter/setter 'year' == 'FullYear')
- makeShortcut('year', 'FullYear');
+ makeGetterAndSetter('year', 'FullYear');
+ moment.duration.fn = Duration.prototype = {
+ weeks : function () {
+ return absRound(this.days() / 7);
+ },
+
+ valueOf : function () {
+ return this._milliseconds +
+ this._days * 864e5 +
+ this._months * 2592e6;
+ },
+
+ humanize : function (withSuffix) {
+ var difference = +this,
+ rel = moment.relativeTime,
+ output = relativeTime(difference, !withSuffix);
+
+ if (withSuffix) {
+ output = (difference <= 0 ? rel.past : rel.future).replace(/%s/i, output);
+ }
+
+ return output;
+ }
+ };
+
+ function makeDurationGetter(name) {
+ moment.duration.fn[name] = function () {
+ return this._data[name];
+ };
+ }
+
+ function makeDurationAsGetter(name, factor) {
+ moment.duration.fn['as' + name] = function () {
+ return +this / factor;
+ };
+ }
+
+ for (i = 0; i < durationGetters.length; i++) {
+ makeDurationGetter(durationGetters[i]);
+ }
+
+ for (i in unitMillisecondFactors) {
+ if (unitMillisecondFactors.hasOwnProperty(i)) {
+ makeDurationAsGetter(i, unitMillisecondFactors[i]);
+ }
+ }
+
// CommonJS module is defined
if (hasModule) {
module.exports = moment;
test.equal(m.minutes(), 59, "set the minutes");
test.equal(m.seconds(), 59, "set the seconds");
test.equal(m.milliseconds(), 999, "set the seconds");
- test.equal(m2.eod(), m2.hours(23).minutes(59).seconds(59).milliseconds(999));
+ test.done();
+ },
+
+ "eod utc" : function(test) {
+ test.expect(1);
+
+ var m2 = moment.utc(new Date(2011, 1, 2, 3, 4, 5, 6));
++ test.equal(m2.eod().valueOf(), m2.hours(23).minutes(59).seconds(59).milliseconds(999).valueOf(), "Eod should equal manual hours/mins/seconds");
+
test.done();
}
};