Search code examples
javascriptluxon

Using Luxon, how can I create a time-only object?


I am building an application which will store the opening hours for a business, e.g. 09:00 -> 17:00

For ease of manipulation, I would like to create a Luxon object for the time only, without associating it with a particular date.

The reason for this is because the data type in the database is time.

I tried this:

DateTime.fromObject({ hour: 9 }

...but ultimately it was associated with today's date:

2022-09-19T10:00:00.000+01:00

Solution

  • Luxon does not include a data structure to represent a date-independent time.