diff --git a/packages/adapters/x-adapter-date-fns-v2/src/AdapterDateFns/AdapterDateFns.ts b/packages/adapters/x-adapter-date-fns-v2/src/AdapterDateFns/AdapterDateFns.ts index 11c07a55fc872..925f4e3b18782 100644 --- a/packages/adapters/x-adapter-date-fns-v2/src/AdapterDateFns/AdapterDateFns.ts +++ b/packages/adapters/x-adapter-date-fns-v2/src/AdapterDateFns/AdapterDateFns.ts @@ -46,7 +46,7 @@ import isWithinInterval from 'date-fns/isWithinInterval'; import defaultLocale from 'date-fns/locale/en-US'; // @ts-ignore import longFormatters from 'date-fns/_lib/format/longFormatters'; -import { AdapterDateFnsBase } from '../AdapterDateFnsBase'; +import { AdapterDateFnsBase } from './AdapterDateFnsBase'; type DateFnsLocale = typeof defaultLocale; diff --git a/packages/adapters/x-adapter-date-fns-v2/src/AdapterDateFnsBase/index.ts b/packages/adapters/x-adapter-date-fns-v2/src/AdapterDateFns/AdapterDateFnsBase.ts similarity index 100% rename from packages/adapters/x-adapter-date-fns-v2/src/AdapterDateFnsBase/index.ts rename to packages/adapters/x-adapter-date-fns-v2/src/AdapterDateFns/AdapterDateFnsBase.ts diff --git a/packages/adapters/x-adapter-date-fns-v3/src/AdapterDateFns/AdapterDateFns.ts b/packages/adapters/x-adapter-date-fns-v3/src/AdapterDateFns/AdapterDateFns.ts index 1fb3f42dc2e9c..fabb034b2f30d 100644 --- a/packages/adapters/x-adapter-date-fns-v3/src/AdapterDateFns/AdapterDateFns.ts +++ b/packages/adapters/x-adapter-date-fns-v3/src/AdapterDateFns/AdapterDateFns.ts @@ -1,52 +1,56 @@ /* eslint-disable class-methods-use-this */ import { AdapterFormats, AdapterOptions, MuiPickersAdapter } from '@mui/x-adapter-common'; -import addDays from 'date-fns/addDays'; -import addSeconds from 'date-fns/addSeconds'; -import addMinutes from 'date-fns/addMinutes'; -import addHours from 'date-fns/addHours'; -import addWeeks from 'date-fns/addWeeks'; -import addMonths from 'date-fns/addMonths'; -import addYears from 'date-fns/addYears'; -import endOfDay from 'date-fns/endOfDay'; -import endOfWeek from 'date-fns/endOfWeek'; -import endOfYear from 'date-fns/endOfYear'; -import { format as dateFnsFormat, longFormatters } from 'date-fns/format'; -import getDate from 'date-fns/getDate'; -import getDaysInMonth from 'date-fns/getDaysInMonth'; -import getHours from 'date-fns/getHours'; -import getMinutes from 'date-fns/getMinutes'; -import getMonth from 'date-fns/getMonth'; -import getSeconds from 'date-fns/getSeconds'; -import getMilliseconds from 'date-fns/getMilliseconds'; -import getWeek from 'date-fns/getWeek'; -import getYear from 'date-fns/getYear'; -import isAfter from 'date-fns/isAfter'; -import isBefore from 'date-fns/isBefore'; -import isEqual from 'date-fns/isEqual'; -import isSameDay from 'date-fns/isSameDay'; -import isSameYear from 'date-fns/isSameYear'; -import isSameMonth from 'date-fns/isSameMonth'; -import isSameHour from 'date-fns/isSameHour'; -import isValid from 'date-fns/isValid'; -import dateFnsParse from 'date-fns/parse'; -import setDate from 'date-fns/setDate'; -import setHours from 'date-fns/setHours'; -import setMinutes from 'date-fns/setMinutes'; -import setMonth from 'date-fns/setMonth'; -import setSeconds from 'date-fns/setSeconds'; -import setMilliseconds from 'date-fns/setMilliseconds'; -import setYear from 'date-fns/setYear'; -import startOfDay from 'date-fns/startOfDay'; -import startOfMonth from 'date-fns/startOfMonth'; -import endOfMonth from 'date-fns/endOfMonth'; -import startOfWeek from 'date-fns/startOfWeek'; -import startOfYear from 'date-fns/startOfYear'; -import isWithinInterval from 'date-fns/isWithinInterval'; -import enUS from 'date-fns/locale/en-US'; -import { Locale as DateFnsLocale } from 'date-fns/locale'; - -import { AdapterDateFnsBase } from '../AdapterDateFnsBase'; +import { + addDays, + addHours, + addMinutes, + addMonths, + addSeconds, + addWeeks, + addYears, + endOfDay, + endOfMonth, + endOfWeek, + endOfYear, + format as dateFnsFormat, + // @ts-ignore + longFormatters, + getDate, + getDaysInMonth, + getHours, + getMilliseconds, + getMinutes, + getMonth, + getSeconds, + getWeek, + getYear, + isAfter, + isBefore, + isEqual, + isSameDay, + isSameHour, + isSameMonth, + isSameYear, + isValid, + isWithinInterval, + Locale as DateFnsLocale, + parse as dateFnsParse, + setDate, + setHours, + setMilliseconds, + setMinutes, + setMonth, + setSeconds, + setYear, + startOfDay, + startOfMonth, + startOfWeek, + startOfYear, +} from 'date-fns'; + +import { enUS } from 'date-fns/locale'; +import { AdapterDateFnsBase } from './AdapterDateFnsBase'; /** * Based on `@date-io/date-fns` @@ -74,7 +78,7 @@ import { AdapterDateFnsBase } from '../AdapterDateFnsBase'; * SOFTWARE. */ export class AdapterDateFns - extends AdapterDateFnsBase + extends AdapterDateFnsBase // @ts-ignore we fix date typings in the x-date-picker package. implements MuiPickersAdapter { diff --git a/packages/adapters/x-adapter-date-fns-v3/src/AdapterDateFnsBase/index.ts b/packages/adapters/x-adapter-date-fns-v3/src/AdapterDateFns/AdapterDateFnsBase.ts similarity index 93% rename from packages/adapters/x-adapter-date-fns-v3/src/AdapterDateFnsBase/index.ts rename to packages/adapters/x-adapter-date-fns-v3/src/AdapterDateFns/AdapterDateFnsBase.ts index 87222600f51eb..40d8a0608e2aa 100644 --- a/packages/adapters/x-adapter-date-fns-v3/src/AdapterDateFnsBase/index.ts +++ b/packages/adapters/x-adapter-date-fns-v3/src/AdapterDateFns/AdapterDateFnsBase.ts @@ -1,5 +1,4 @@ /* eslint-disable class-methods-use-this */ - import { AdapterFormats, AdapterOptions, @@ -7,18 +6,10 @@ import { FieldFormatTokenMap, MuiPickersAdapter, } from '@mui/x-adapter-common'; +import { Locale as DateFnsLocale } from 'date-fns'; export type MakeRequired = Omit & Required>; -type DateFnsLocaleBase = { - formatLong?: { - date?: any; - time?: any; - dateTime?: any; - }; - code?: string; -}; - const formatTokenMap: FieldFormatTokenMap = { // Year y: { sectionType: 'year', contentType: 'digit', maxLength: 4 }, @@ -113,10 +104,7 @@ const defaultFormats: AdapterFormats = { keyboardDateTime24h: 'P HH:mm', }; -type DateFnsAdapterBaseOptions = MakeRequired< - AdapterOptions, - 'locale' -> & { +type DateFnsAdapterBaseOptions = MakeRequired, 'locale'> & { longFormatters: Record<'p' | 'P', (token: string, formatLong: any) => string>; }; @@ -145,7 +133,7 @@ type DateFnsAdapterBaseOptions = MakeRe * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -export class AdapterDateFnsBase +export class AdapterDateFnsBase implements Pick< // @ts-ignore we fix date typings in the x-date-picker package. @@ -175,9 +163,9 @@ export class AdapterDateFnsBase public escapedCharacters = { start: "'", end: "'" }; - public longFormatters: DateFnsAdapterBaseOptions['longFormatters']; + public longFormatters: DateFnsAdapterBaseOptions['longFormatters']; - constructor(props: DateFnsAdapterBaseOptions) { + constructor(props: DateFnsAdapterBaseOptions) { const { locale, formats, longFormatters } = props; this.locale = locale; this.formats = { ...defaultFormats, ...formats };