Last active
October 15, 2015 14:25
-
-
Save ptasker/892a23d3601643b995de to your computer and use it in GitHub Desktop.
Date range
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var monthArray = []; | |
for(var i in monthly){ | |
var month = monthly[i].split('-')[1]; | |
monthArray.push(months[month]); | |
} | |
currStartMonth = monthly[0]; | |
currEndMonth = monthly[1]; | |
// currStartMonth = (monthArray[0] > monthArray[1])? monthArray[1] : monthArray[0]; | |
// currEndMonth = (monthArray[1] > monthArray[0])? monthArray[1] : monthArray[0]; | |
// | |
// var monthRange = (currEndMonth - currStartMonth) + 1; | |
// | |
// prevStartMonth = currStartMonth - monthRange; | |
// prevEndMonth = (prevStartMonth + monthRange) - 1; | |
/** | |
* | |
* Using a date formation of YYYY-MMMM | |
* | |
* EX. 2015-August | |
* | |
*/ | |
//Create moment objects based on current dates passed in. | |
var startDate = moment(currStartMonth, 'YYYY-MMMM'), | |
endDate = moment(currEndMonth, 'YYYY-MMMM'), | |
//Get the differenece beween the 2 dates, in months | |
diffInMonths = endDate.diff(startDate, 'months'); | |
//Get the previous start month by subtracting the difference in months (plus 1 month to offset from the current start month) | |
prevStartMonth = moment(currStartMonth).subtract(diffInMonths + 1, 'months').format('YYYY-MMMM'); | |
//Get the previous 'end' month by adding in the original difference to the previous start month. | |
prevEndMonth = moment(prevStartMonth).add(diffInMonths, 'months').format('YYYY-MMMM'); | |
selectTypeMonth = 'range'; | |
console.info(currStartMonth,currEndMonth," - ",prevStartMonth,prevEndMonth); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment