Home > Software design >  Obtain Duration of a quarter in Luxon
Obtain Duration of a quarter in Luxon

Time:02-19

I'm trying to obtain the Duration (or start and end dates) of an arbitrary 'quarter' in Luxon.

For example, suppose I want the beginning and ending dates of the 3rd quarter knowing only the quarter:

const quarterInQuestion = 3;

const startDateOfQuarter = DateTime.fromFormat(quarterInQuestion.toString(), 'q');

This will give me the start date of the quarter, but how can I obtain the end date as well. I've looked into Durations and Intervals but can't seem to get anything to work yet.

Many thanks!

CodePudding user response:

I think you want the endOf method, to which you can pass the period that you want the end of from a date.

const startDateOfQuarter = DateTime.fromFormat('3', 'q');
const endDateOfQuarter = startDateOfQuarter.endOf('quarter')
  • Related