Skip to content

get end of quarter? #7039

Answered by reidbarber
J4v4Scr1pt asked this question in Q&A
Sep 16, 2024 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

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()));

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@J4v4Scr1pt
Comment options

@reidbarber
Comment options

@J4v4Scr1pt
Comment options

Answer selected by J4v4Scr1pt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants