Created
February 24, 2014 19:26
-
-
Save canuk/9195138 to your computer and use it in GitHub Desktop.
Moment.js Fiscal Year Calculations (FY starts in October)
This file contains hidden or 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
if (moment().quarter() == 4) { | |
var current_fiscal_year_start = moment().month('October').startOf('month'); | |
var current_fiscal_year_end = moment().add('year', 1).month('September').endOf('month'); | |
var last_fiscal_year_start = moment().subtract('year', 1).month('October').startOf('month'); | |
var last_fiscal_year_end = moment().month('September').endOf('month'); | |
} else { | |
var current_fiscal_year_start = moment().subtract('year', 1).month('October').startOf('month'); | |
var current_fiscal_year_end = moment().month('September').endOf('month'); | |
var last_fiscal_year_start = moment().subtract('year', 2).month('October').startOf('month'); | |
var last_fiscal_year_end = moment().subtract('year', 1).month('September').endOf('month'); | |
}; |
Thanks!! Works Great!
const getFiscalYearTimestamps = () => {
const startMonthName = "October";
const endMonthName = "September";
if (moment().quarter() == 4) {
return {
current: {
start: moment().month(startMonthName).startOf('month'),
end: moment().add(1, 'year').month(endMonthName).endOf('month')
},
last: {
start: moment().subtract(1, 'year').month(startMonthName).startOf('month'),
end: moment().month(endMonthName).endOf('month')
}
};
} else {
return {
current: {
start: moment().subtract(1, 'year').month(startMonthName).startOf('month'),
end: moment().month(endMonthName).endOf('month')
},
last: {
start: moment().subtract(2, 'year').month(startMonthName).startOf('month'),
end: moment().subtract(1, 'year').month(endMonthName).endOf('month')
}
};
}
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wrote this to complement https://github.com/dangrossman/bootstrap-daterangepicker