From: Tim Wood Date: Thu, 10 Jan 2013 19:19:50 +0000 (-0800) Subject: deprecating eod and sod X-Git-Tag: 2.0.0~7^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=712b8314111ea692d37cc7d5d4a3a19422974636;p=thirdparty%2Fmoment.git deprecating eod and sod --- diff --git a/moment.js b/moment.js index 1d9cbcf84..001ed56b0 100644 --- a/moment.js +++ b/moment.js @@ -1122,7 +1122,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' : @@ -1193,15 +1193,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(); }, diff --git a/test/moment/lang.js b/test/moment/lang.js index a5d7328fd..3799a7e6e 100644 --- a/test/moment/lang.js +++ b/test/moment/lang.js @@ -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(); }, diff --git a/test/moment/mutable.js b/test/moment/mutable.js index 4d45c94b1..182700ea0 100644 --- a/test/moment/mutable.js +++ b/test/moment/mutable.js @@ -2,7 +2,7 @@ var moment = require("../../moment"); exports.mutable = { "manipulation methods" : function (test) { - + var mutableMethods = { 'year': function (m){ return m.year(2011); }, 'month': function (m){ return m.month(1); }, @@ -34,13 +34,12 @@ 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)) { diff --git a/test/moment/sod_eod.js b/test/moment/sod_eod.js index fd3a85688..b1420f03f 100644 --- a/test/moment/sod_eod.js +++ b/test/moment/sod_eod.js @@ -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); @@ -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); @@ -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); @@ -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); @@ -95,13 +58,13 @@ 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(); }, - + "start of day" : function(test) { test.expect(8); @@ -111,13 +74,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); @@ -127,13 +90,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); @@ -143,13 +106,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); @@ -159,13 +122,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); @@ -175,13 +138,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); @@ -191,13 +154,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); @@ -207,13 +170,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); @@ -223,9 +186,9 @@ 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(); },