Skip to content

Commit

Permalink
Deprecated MomentJS methods
Browse files Browse the repository at this point in the history
MomentJS has deprecated pre-2.0 syntax for add/subtract methods. See
moment/moment#1763.
  • Loading branch information
cwackerman committed Sep 23, 2014
1 parent d779645 commit f30a4ba
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 33 deletions.
4 changes: 2 additions & 2 deletions clndr.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<script src="json2.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>
<script src= "moment-2.5.1.js"></script>
<script src= "moment-2.8.3.js"></script>

<script src="../src/clndr.js"></script>
<script src="site.js"></script>
Expand Down
6 changes: 0 additions & 6 deletions example/moment-2.5.1.js

This file was deleted.

7 changes: 7 additions & 0 deletions example/moment-2.8.3.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ $(document).ready( function() {
startDate: 'startDate',
endDate: 'endDate'
},
startWithMonth: moment().add('month', 1),
startWithMonth: moment().add(1, 'month'),
clickEvents: {
click: function(target) {
console.log(target);
Expand Down
2 changes: 1 addition & 1 deletion example/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h4>These are the tests. If you are contributing to clndr.js, please take the ti
<script src="json2.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>
<script src= "moment-2.5.1.js"></script>
<script src= "moment-2.8.3.js"></script>

<script src="../src/clndr.js"></script>
<script src="test.js"></script>
Expand Down
8 changes: 4 additions & 4 deletions example/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ $( function() {
// test really long multi-day events
// ================================================================================
var multidayLongArray = [
{ startDate: moment().subtract('months', 3).format('YYYY-MM-') + '12', endDate: moment().format('YYYY-MM-') + '17', title: 'Multi1' },
{ startDate: moment().format('YYYY-MM-') + '24', endDate: moment().add('months', 4).format('YYYY-MM-') + '27', title: 'Multi2' }
{ startDate: moment().subtract(3, 'months').format('YYYY-MM-') + '12', endDate: moment().format('YYYY-MM-') + '17', title: 'Multi1' },
{ startDate: moment().format('YYYY-MM-') + '24', endDate: moment().add(4, 'months').format('YYYY-MM-') + '27', title: 'Multi2' }
];

clndr.multidayLong = $('#multiday-long').clndr({
Expand All @@ -112,7 +112,7 @@ $( function() {
clndr.constraints = $('#constraints').clndr({
constraints: {
startDate: moment().format('YYYY-MM-') + '04',
endDate: moment().add('months', 1).format('YYYY-MM-12')
endDate: moment().add(1, 'months').format('YYYY-MM-12')
},
clickEvents: {
click: function(target) {
Expand All @@ -139,7 +139,7 @@ $( function() {
// ================================================================================
clndr.endConstriant = $('#end-constraint').clndr({
constraints: {
endDate: moment().add('months', 1).format('YYYY-MM-') + '12'
endDate: moment().add(1, 'months').format('YYYY-MM-') + '12'
}
});

Expand Down
36 changes: 18 additions & 18 deletions src/clndr.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@
}).toArray();

if(this.options.showAdjacentMonths) {
var lastMonth = currentMonth.clone().subtract('months', 1);
var nextMonth = currentMonth.clone().add('months', 1);
var lastMonth = currentMonth.clone().subtract(1, 'months');
var nextMonth = currentMonth.clone().add(1, 'months');
this.eventsLastMonth = $(this.options.events).filter( function() {
// return this._clndrStartDateObject.format("YYYY-MM") <= lastMonth.format("YYYY-MM")
// || lastMonth.format("YYYY-MM") <= this._clndrEndDateObject.format("YYYY-MM");
Expand Down Expand Up @@ -284,8 +284,8 @@

// filter the adjacent months as well, if the option is true
if(this.options.showAdjacentMonths) {
var lastMonth = currentMonth.clone().subtract('months', 1);
var nextMonth = currentMonth.clone().add('months', 1);
var lastMonth = currentMonth.clone().subtract(1, 'months');
var nextMonth = currentMonth.clone().add(1, 'months');
this.eventsLastMonth = $(this.options.events).filter( function() {
return this._clndrDateObject.format("YYYY-MM") == lastMonth.format("YYYY-MM");
}).toArray();
Expand Down Expand Up @@ -337,11 +337,11 @@
// if we want to force six rows of calendar, now's our last chance to add another row.
// if the 42 seems explicit it's because we're creating a 7-row grid and 6 rows of 7 is always 42!
if(this.options.forceSixRows && daysArray.length !== 42 ) {
var start = moment(daysArray[daysArray.length - 1].date).add('days', 1);
var start = moment(daysArray[daysArray.length - 1].date).add(1, 'days');
while(daysArray.length < 42) {
if(this.options.showAdjacentMonths) {
daysArray.push( this.createDayObject(moment(start), this.eventsNextMonth) );
start.add('days', 1);
start.add(1, 'days');
} else {
daysArray.push( this.calendarDay({ classes: this.options.targets.empty + " next-month" }) );
}
Expand Down Expand Up @@ -490,11 +490,11 @@
this.element.find('.' + this.options.targets.nextButton).toggleClass('inactive', true);
}
// what's last year looking like?
if(start && moment(start).subtract('years', 1).isBefore(moment(this.month).subtract('years', 1)) ) {
if(start && moment(start).subtract(1, 'years').isBefore(moment(this.month).subtract(1, 'years')) ) {
this.element.find('.' + this.options.targets.previousYearButton).toggleClass('inactive', true);
}
// how about next year?
if(end && moment(end).add('years', 1).isAfter(moment(this.month).add('years', 1)) ) {
if(end && moment(end).add(1, 'years').isAfter(moment(this.month).add(1, 'years')) ) {
this.element.find('.' + this.options.targets.nextYearButton).toggleClass('inactive', true);
}
// today? we could put this in init(), but we want to support the user changing the constraints on a living instance.
Expand Down Expand Up @@ -622,8 +622,8 @@
}

// is subtracting one month going to switch the year?
var yearChanged = !self.month.isSame( moment(self.month).subtract('months', 1), 'year');
self.month.subtract('months', 1);
var yearChanged = !self.month.isSame( moment(self.month).subtract(1, 'months'), 'year');
self.month.subtract(1, 'months');

self.render();

Expand All @@ -648,8 +648,8 @@
}

// is adding one month going to switch the year?
var yearChanged = !self.month.isSame( moment(self.month).add('months', 1), 'year');
self.month.add('months', 1);
var yearChanged = !self.month.isSame( moment(self.month).add(1, 'months'), 'year');
self.month.add(1, 'months');

self.render();

Expand Down Expand Up @@ -706,7 +706,7 @@
return;
}

self.month.add('years', 1);
self.month.add(1, 'years');
self.render();

if(self.options.clickEvents.nextYear) {
Expand All @@ -728,7 +728,7 @@
return;
}

self.month.subtract('years', 1);
self.month.subtract(1, 'years');
self.render();

if(self.options.clickEvents.previousYear) {
Expand All @@ -743,7 +743,7 @@
};

Clndr.prototype.forward = function(options) {
this.month.add('months', 1);
this.month.add(1, 'months');
this.render();
if(options && options.withCallbacks) {
if(this.options.clickEvents.onMonthChange) {
Expand All @@ -760,7 +760,7 @@
}

Clndr.prototype.back = function(options) {
this.month.subtract('months', 1);
this.month.subtract(1, 'months');
this.render();
if(options && options.withCallbacks) {
if(this.options.clickEvents.onMonthChange) {
Expand Down Expand Up @@ -800,7 +800,7 @@
}

Clndr.prototype.nextYear = function(options) {
this.month.add('year', 1);
this.month.add(1, 'year');
this.render();
if(options && options.withCallbacks) {
if(this.options.clickEvents.onYearChange) {
Expand All @@ -811,7 +811,7 @@
}

Clndr.prototype.previousYear = function(options) {
this.month.subtract('year', 1);
this.month.subtract(1, 'year');
this.render();
if(options && options.withCallbacks) {
if(this.options.clickEvents.onYearChange) {
Expand Down

0 comments on commit f30a4ba

Please sign in to comment.