Luxon Adapter
The Luxon adapter allows you to use the Luxon library with Angular Material date components like Datepicker and Timepicker. Source:/home/daytona/workspace/source/src/material-luxon-adapter/adapter/luxon-date-adapter.ts
Installation
Setup
Standalone Components
Provide the adapter in your component or at the application level:NgModule
Provide the adapter in your module:Adapter Options
Configure the adapter usingMAT_LUXON_DATE_ADAPTER_OPTIONS:
Option Properties
Source:/home/daytona/workspace/source/src/material-luxon-adapter/adapter/luxon-date-adapter.ts:18
useUtc(boolean) - Use UTC dates instead of local time. Default:falsefirstDayOfWeek(number) - First day of week (0-6, Sunday=0). If not set, uses locale defaultdefaultOutputCalendar(string) - Output calendar system. Default:'gregory'
Localization
Set the locale usingMAT_DATE_LOCALE:
en-US- English (US)en-GB- English (UK)es- Spanishfr- Frenchde- Germanja- Japanesezh-CN- Chinese (Simplified)- And many more…
UTC Mode
When working with UTC dates:Custom Date Formats
Customize how dates are displayed and parsed:LuxonDateAdapter API
TheLuxonDateAdapter class extends Angular Material’s DateAdapter.
Key Methods
Implemented from/home/daytona/workspace/source/src/material-luxon-adapter/adapter/luxon-date-adapter.ts:62:
getYear(date: DateTime): number- Get the yeargetMonth(date: DateTime): number- Get the month (0-11, Luxon uses 1-12 internally)getDate(date: DateTime): number- Get the day of monthgetDayOfWeek(date: DateTime): number- Get day of weekgetMonthNames(style)- Get month namesgetDateNames()- Get array of date namesgetDayOfWeekNames(style)- Get day namesgetYearName(date: DateTime): string- Get year as stringgetFirstDayOfWeek(): number- Get first day of weekgetNumDaysInMonth(date: DateTime): number- Get days in monthclone(date: DateTime): DateTime- Clone a datecreateDate(year, month, date): DateTime- Create a new datetoday(): DateTime- Get today’s dateparse(value, parseFormat)- Parse a date stringformat(date, displayFormat): string- Format a dateaddCalendarYears(date, years): DateTime- Add yearsaddCalendarMonths(date, months): DateTime- Add monthsaddCalendarDays(date, days): DateTime- Add daystoIso8601(date): string- Convert to ISO 8601 stringisDateInstance(obj): boolean- Check if value is a DateTimeisValid(date): boolean- Check if date is validinvalid(): DateTime- Create an invalid date
Time Support
setTime(target, hours, minutes, seconds): DateTimegetHours(date): numbergetMinutes(date): numbergetSeconds(date): numberparseTime(value, parseFormat)addSeconds(date, amount): DateTime
Luxon Format Tokens
Luxon uses specific format tokens:D- Short date (e.g., 4/29/2023)DD- Medium date (e.g., Apr 29, 2023)DDD- Long date (e.g., April 29, 2023)DDDD- Full date (e.g., Saturday, April 29, 2023)t- Short time (e.g., 9:30 AM)tt- Medium time (e.g., 9:30:00 AM)yyyy- 4-digit yearyy- 2-digit yearMM- 2-digit monthM- Month numberMMMM- Full month nameMMM- Short month namedd- 2-digit dayd- Day numberEEEE- Full day nameEEE- Short day name
Example with Datepicker
Calendar Systems
Luxon supports different calendar systems:gregory- Gregorian (default)islamic- Islamichebrew- Hebrewbuddhist- Buddhistchinese- Chinesecoptic- Copticethiopic- Ethiopicindian- Indianjapanese- Japanesepersian- Persian
Working with Luxon DateTime
Why Use Luxon?
- Modern: Built for modern JavaScript (ES6+)
- Immutable: All operations return new objects
- Chainable: Fluent API for easy composition
- Time zones: First-class time zone support
- i18n: Built-in internationalization
- Type-safe: Written in TypeScript
- Successor to Moment: Created by a Moment.js maintainer
Comparison with Other Adapters
| Feature | Luxon | Moment.js | date-fns |
|---|---|---|---|
| Bundle size | Medium | Large | Small |
| Tree-shaking | Yes | No | Yes |
| Immutable | Yes | No* | Yes |
| Time zones | Excellent | Good | Limited |
| i18n | Built-in | Built-in | Separate |
| Active | Yes | Deprecated | Yes |