get end of quarter? #7039
Answered
by
reidbarber
J4v4Scr1pt
asked this question in
Q&A
-
Hi! I currently trying to replace our dependencie on dayJs and replace it with internationalized/date. I have searched the docs and looked at the code, but can't find anything that would help finding a solution to this. Any ideas would be much appreciated! |
Beta Was this translation helpful? Give feedback.
Answered by
reidbarber
Sep 16, 2024
Replies: 1 comment 3 replies
-
This isn't built into the library, but you should be able to create a utility function like this: import {CalendarDate, today, getLocalTimeZone} from '@internationalized/date'
function getEndOfQuarter(date: CalendarDate) {
const currentQuarter = Math.floor((date.month - 1) / 3) + 1;
const lastMonthOfQuarter = currentQuarter * 3;
const firstDayOfLastMonth = new CalendarDate(date.year, lastMonthOfQuarter, 1);
const firstDayOfNextMonth = firstDayOfLastMonth.add({months: 1});
const lastDayOfQuarter = firstDayOfNextMonth.subtract({days: 1});
return lastDayOfQuarter;
}
const endOfQuarter = getEndOfQuarter(today(getLocalTimeZone())); |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
J4v4Scr1pt
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This isn't built into the library, but you should be able to create a utility function like this: