CalendarUtils module provides utility functions for date formatting and manipulation, as well as helper functions for working with calendar components.
Import
Functions
getCalendarDateString
Converts various date formats to a calendar date string in ‘yyyy-MM-dd’ format.Date value to convert. Can be:
- JavaScript Date object
- Date string
- Timestamp number
- undefined (returns undefined)
string | undefined - Date string in ‘yyyy-MM-dd’ format or undefined
getDefaultLocale
Gets the current default locale configuration from XDate. Returns:object - Current locale configuration object
Higher-order components
asCalendarConsumer
Higher-order component that wraps a component to provide CalendarContext as a prop. Useful for class components that need access to calendar context.Calendar context object with the following properties:
date- Current visible dateprevDate- Previous dateselectedDate- Currently selected dateupdateSource- Source of last updatesetDate- Method to update the datesetDisabled- Method to enable/disable today buttonnumberOfDays- Number of days in timeline modetimelineLeftInset- Timeline sidebar width
Usage examples
Converting dates for calendar
Working with locale information
Class component with calendar context
TypeScript types
Related
- CalendarContext - Calendar context for functional components
- CalendarProvider - Context provider component
- LocaleConfig - Configure calendar localization