risingTide
risingTide

Reputation: 1896

Obtain Duration of a quarter in Luxon

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!

Upvotes: 0

Views: 1811

Answers (1)

Alex Wayne
Alex Wayne

Reputation: 187134

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')

Upvotes: 5

Related Questions