Skip to content

Commit

Permalink
merging moment#572
Browse files Browse the repository at this point in the history
  • Loading branch information
timrwood committed Feb 5, 2013
2 parents 5e95d7a + e9432ea commit 97e3069
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 160 deletions.
18 changes: 1 addition & 17 deletions moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -990,13 +990,6 @@
return ret;
};

// humanizeDuration
// This method is deprecated in favor of the new Duration object. Please
// see the moment.duration method.
moment.humanizeDuration = function (num, type, withSuffix) {
return moment.duration(num, type === true ? null : type).humanize(type === true ? true : withSuffix);
};

// version number
moment.version = VERSION;

Expand Down Expand Up @@ -1171,7 +1164,7 @@
},

calendar : function () {
var diff = this.diff(moment().sod(), 'days', true),
var diff = this.diff(moment().startOf('day'), 'days', true),
format = diff < -6 ? 'sameElse' :
diff < -1 ? 'lastWeek' :
diff < 0 ? 'lastDay' :
Expand Down Expand Up @@ -1250,15 +1243,6 @@
return +this.clone().startOf(units) === +moment(input).startOf(units);
},

sod: function () {
return this.clone().startOf('day');
},

eod: function () {
// end of day = start of day plus 1 day, minus 1 millisecond
return this.clone().endOf('day');
},

zone : function () {
return this._isUTC ? 0 : this._d.getTimezoneOffset();
},
Expand Down
52 changes: 0 additions & 52 deletions test/moment/humanize_duration.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/moment/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ exports.lang = {

test.equal(moment([2012, 5, 6]).lang('es').add({days: 1}).format('MMMM'), 'junio', 'With addition');
test.equal(moment([2012, 5, 6]).lang('es').day(0).format('MMMM'), 'junio', 'With day getter');
test.equal(moment([2012, 5, 6]).lang('es').eod().format('MMMM'), 'junio', 'With eod');
test.equal(moment([2012, 5, 6]).lang('es').endOf('day').format('MMMM'), 'junio', 'With endOf');

test.done();
},
Expand Down
5 changes: 2 additions & 3 deletions test/moment/mutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ exports.mutable = {
"non mutable methods" : function (test) {

var nonMutableMethods = {
'sod': function (m){ return m.sod() },
'eod': function (m){ return m.eod() }
'clone': function (m){ return m.clone() }
};

test.expect(2);
test.expect(1);

for (method in nonMutableMethods){
if (nonMutableMethods.hasOwnProperty(method)) {
Expand Down
137 changes: 50 additions & 87 deletions test/moment/sod_eod.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,6 @@
var moment = require("../../moment");

exports.eod_sod = {
"sod" : function(test) {
test.expect(7);

var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).sod();
test.equal(m.year(), 2011, "keep the year");
test.equal(m.month(), 1, "keep the month");
test.equal(m.date(), 2, "keep the day");
test.equal(m.hours(), 0, "strip out the hours");
test.equal(m.minutes(), 0, "strip out the minutes");
test.equal(m.seconds(), 0, "strip out the seconds");
test.equal(m.milliseconds(), 0, "strip out the milliseconds");
test.done();
},

"eod" : function(test) {
test.expect(7);

var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).eod();
test.equal(m.year(), 2011, "keep the year");
test.equal(m.month(), 1, "keep the month");
test.equal(m.date(), 2, "keep the day");
test.equal(m.hours(), 23, "set the hours");
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.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();
},

exports.end_start_of = {
"start of year" : function(test) {
test.expect(8);

Expand All @@ -47,13 +10,13 @@ exports.eod_sod = {
test.equal(m.year(), 2011, "keep the year");
test.equal(m.month(), 0, "strip out the month");
test.equal(m.date(), 1, "strip out the day");
test.equal(m.hours(), 0, "strip out the hours");
test.equal(m.minutes(), 0, "strip out the minutes");
test.equal(m.seconds(), 0, "strip out the seconds");
test.equal(m.hours(), 0, "strip out the hours");
test.equal(m.minutes(), 0, "strip out the minutes");
test.equal(m.seconds(), 0, "strip out the seconds");
test.equal(m.milliseconds(), 0, "strip out the milliseconds");
test.done();
},

"end of year" : function(test) {
test.expect(8);

Expand All @@ -63,13 +26,13 @@ exports.eod_sod = {
test.equal(m.year(), 2011, "keep the year");
test.equal(m.month(), 11, "set the month");
test.equal(m.date(), 31, "set the day");
test.equal(m.hours(), 23, "set the hours");
test.equal(m.minutes(), 59, "set the minutes");
test.equal(m.seconds(), 59, "set the seconds");
test.equal(m.hours(), 23, "set the hours");
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.done();
},

"start of month" : function(test) {
test.expect(8);

Expand All @@ -79,13 +42,13 @@ exports.eod_sod = {
test.equal(m.year(), 2011, "keep the year");
test.equal(m.month(), 1, "keep the month");
test.equal(m.date(), 1, "strip out the day");
test.equal(m.hours(), 0, "strip out the hours");
test.equal(m.minutes(), 0, "strip out the minutes");
test.equal(m.seconds(), 0, "strip out the seconds");
test.equal(m.hours(), 0, "strip out the hours");
test.equal(m.minutes(), 0, "strip out the minutes");
test.equal(m.seconds(), 0, "strip out the seconds");
test.equal(m.milliseconds(), 0, "strip out the milliseconds");
test.done();
},

"end of month" : function(test) {
test.expect(8);

Expand All @@ -95,9 +58,9 @@ exports.eod_sod = {
test.equal(m.year(), 2011, "keep the year");
test.equal(m.month(), 1, "keep the month");
test.equal(m.date(), 28, "set the day");
test.equal(m.hours(), 23, "set the hours");
test.equal(m.minutes(), 59, "set the minutes");
test.equal(m.seconds(), 59, "set the seconds");
test.equal(m.hours(), 23, "set the hours");
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.done();
},
Expand All @@ -118,7 +81,7 @@ exports.eod_sod = {
test.equal(m.milliseconds(), 0, "strip out the milliseconds");
test.done();
},

"end of week" : function(test) {
test.expect(9);

Expand All @@ -135,7 +98,7 @@ exports.eod_sod = {
test.equal(m.milliseconds(), 999, "set the seconds");
test.done();
},

"start of day" : function(test) {
test.expect(8);

Expand All @@ -145,13 +108,13 @@ exports.eod_sod = {
test.equal(m.year(), 2011, "keep the year");
test.equal(m.month(), 1, "keep the month");
test.equal(m.date(), 2, "keep the day");
test.equal(m.hours(), 0, "strip out the hours");
test.equal(m.minutes(), 0, "strip out the minutes");
test.equal(m.seconds(), 0, "strip out the seconds");
test.equal(m.hours(), 0, "strip out the hours");
test.equal(m.minutes(), 0, "strip out the minutes");
test.equal(m.seconds(), 0, "strip out the seconds");
test.equal(m.milliseconds(), 0, "strip out the milliseconds");
test.done();
},

"end of day" : function(test) {
test.expect(8);

Expand All @@ -161,13 +124,13 @@ exports.eod_sod = {
test.equal(m.year(), 2011, "keep the year");
test.equal(m.month(), 1, "keep the month");
test.equal(m.date(), 2, "keep the day");
test.equal(m.hours(), 23, "set the hours");
test.equal(m.minutes(), 59, "set the minutes");
test.equal(m.seconds(), 59, "set the seconds");
test.equal(m.hours(), 23, "set the hours");
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.done();
},

"start of hour" : function(test) {
test.expect(8);

Expand All @@ -177,13 +140,13 @@ exports.eod_sod = {
test.equal(m.year(), 2011, "keep the year");
test.equal(m.month(), 1, "keep the month");
test.equal(m.date(), 2, "keep the day");
test.equal(m.hours(), 3, "keep the hours");
test.equal(m.minutes(), 0, "strip out the minutes");
test.equal(m.seconds(), 0, "strip out the seconds");
test.equal(m.hours(), 3, "keep the hours");
test.equal(m.minutes(), 0, "strip out the minutes");
test.equal(m.seconds(), 0, "strip out the seconds");
test.equal(m.milliseconds(), 0, "strip out the milliseconds");
test.done();
},

"end of hour" : function(test) {
test.expect(8);

Expand All @@ -193,13 +156,13 @@ exports.eod_sod = {
test.equal(m.year(), 2011, "keep the year");
test.equal(m.month(), 1, "keep the month");
test.equal(m.date(), 2, "keep the day");
test.equal(m.hours(), 3, "keep the hours");
test.equal(m.minutes(), 59, "set the minutes");
test.equal(m.seconds(), 59, "set the seconds");
test.equal(m.hours(), 3, "keep the hours");
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.done();
},

"start of minute" : function(test) {
test.expect(8);

Expand All @@ -209,13 +172,13 @@ exports.eod_sod = {
test.equal(m.year(), 2011, "keep the year");
test.equal(m.month(), 1, "keep the month");
test.equal(m.date(), 2, "keep the day");
test.equal(m.hours(), 3, "keep the hours");
test.equal(m.minutes(), 4, "keep the minutes");
test.equal(m.seconds(), 0, "strip out the seconds");
test.equal(m.hours(), 3, "keep the hours");
test.equal(m.minutes(), 4, "keep the minutes");
test.equal(m.seconds(), 0, "strip out the seconds");
test.equal(m.milliseconds(), 0, "strip out the milliseconds");
test.done();
},

"end of minute" : function(test) {
test.expect(8);

Expand All @@ -225,13 +188,13 @@ exports.eod_sod = {
test.equal(m.year(), 2011, "keep the year");
test.equal(m.month(), 1, "keep the month");
test.equal(m.date(), 2, "keep the day");
test.equal(m.hours(), 3, "keep the hours");
test.equal(m.minutes(), 4, "keep the minutes");
test.equal(m.seconds(), 59, "set the seconds");
test.equal(m.hours(), 3, "keep the hours");
test.equal(m.minutes(), 4, "keep the minutes");
test.equal(m.seconds(), 59, "set the seconds");
test.equal(m.milliseconds(), 999, "set the seconds");
test.done();
},

"start of second" : function(test) {
test.expect(8);

Expand All @@ -241,13 +204,13 @@ exports.eod_sod = {
test.equal(m.year(), 2011, "keep the year");
test.equal(m.month(), 1, "keep the month");
test.equal(m.date(), 2, "keep the day");
test.equal(m.hours(), 3, "keep the hours");
test.equal(m.minutes(), 4, "keep the minutes");
test.equal(m.seconds(), 5, "keep the the seconds");
test.equal(m.hours(), 3, "keep the hours");
test.equal(m.minutes(), 4, "keep the minutes");
test.equal(m.seconds(), 5, "keep the the seconds");
test.equal(m.milliseconds(), 0, "strip out the milliseconds");
test.done();
},

"end of second" : function(test) {
test.expect(8);

Expand All @@ -257,10 +220,10 @@ exports.eod_sod = {
test.equal(m.year(), 2011, "keep the year");
test.equal(m.month(), 1, "keep the month");
test.equal(m.date(), 2, "keep the day");
test.equal(m.hours(), 3, "keep the hours");
test.equal(m.minutes(), 4, "keep the minutes");
test.equal(m.seconds(), 5, "keep the seconds");
test.equal(m.hours(), 3, "keep the hours");
test.equal(m.minutes(), 4, "keep the minutes");
test.equal(m.seconds(), 5, "keep the seconds");
test.equal(m.milliseconds(), 999, "set the seconds");
test.done();
},
}
};

0 comments on commit 97e3069

Please sign in to comment.