Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Many thanks!

>Solution :

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')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading