@weekwise/adapter-luxon 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/LICENSE
CHANGED
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["Info","isString","DateTime","luxon","_weekwise_core","DEFAULT_FORMATS","LuxonAdapter","options","proto","name","descriptor","locale","overrides","key","formatOrPatternKey","value","left","right","unit","date","millis","dateString","weekStart","day","period","yearStart","count","year","month","hour","minute","second","millisecond","date1","date2","isSame","start","end"],"sources":["../src/LuxonAdapter.ts"],"sourcesContent":["import { DateTime, Info, type DateTimeUnit } from \"luxon\";\n\nimport {\n isString,\n type DateAdapter,\n type DateFormatPattern,\n type DateFormatPatterns,\n type WeekDay,\n} from \"@weekwise/core\";\n\ntype DateInput = Date | number | string;\n\nexport interface LuxonAdapterOptions {\n /**\n * BCP 47 locale, e.g. `\"ru\"`, `\"en-US\"`: month and weekday names, date/time formats and the\n * first day of the week come from the browser's Intl data, so no locale files are imported.\n * The calendar picks its interface language by it too. Defaults to `\"en-GB\"`.\n *\n * @example\n * new LuxonAdapter({ locale: \"ru\" });\n */\n locale?: string;\n /**\n * IANA time zone the calendar shows, e.g. `\"America/New_York\"`: days start at its midnight\n * and times are its wall-clock times. Dates stay `Date`s (moments in time). Defaults to the\n * runtime's zone.\n */\n timeZone?: string;\n /** Overrides of the built-in patterns, in Luxon tokens: `{ timeShort: \"h:mm a\" }`. */\n formats?: Partial<DateFormatPatterns>;\n}\n\n/**\n * Built-in patterns. `D`/`DDD` (date), `t`/`tt` (time) and `f`/`F`/`ff` (date and time) are\n * Luxon macro tokens, so every locale gets its own order, separators and 12/24-hour clock.\n */\nconst DEFAULT_FORMATS: DateFormatPatterns = {\n dayNum: \"dd\",\n weekdayLong: \"cccc\",\n weekdayShort: \"ccc\",\n monthLong: \"LLLL\",\n month: \"LLL\",\n dateTimeShort: \"f\",\n dateTime: \"F\",\n dateTimeLong: \"ff\",\n date: \"D\",\n dateLong: \"DDD\",\n dateShort: \"d MMMM\",\n time: \"tt\",\n timeShort: \"t\",\n timeCompact: \"t\",\n};\n\n/**\n * {@link DateAdapter} implementation backed by Luxon.\n */\nexport default class LuxonAdapter implements DateAdapter {\n readonly locale: string;\n readonly weekStartsOn: WeekDay;\n readonly timeZone?: string;\n readonly formatPatterns: DateFormatPatterns;\n\n constructor(options: LuxonAdapterOptions = {}) {\n this.locale = options.locale ?? \"en-GB\";\n this.timeZone = options.timeZone;\n // Luxon numbers weekdays 1 (Monday) … 7 (Sunday)\n this.weekStartsOn = (Info.getStartOfWeek({ locale: this.locale }) % 7) as WeekDay;\n this.formatPatterns = { ...DEFAULT_FORMATS, ...options.formats };\n\n // The calendar destructures adapter methods (`const { format } = adapter`)\n for (let proto = Object.getPrototypeOf(this); proto && proto !== Object.prototype; proto = Object.getPrototypeOf(proto)) {\n for (const name of Object.getOwnPropertyNames(proto)) {\n const descriptor = Object.getOwnPropertyDescriptor(proto, name);\n if (name !== \"constructor\" && typeof descriptor?.value === \"function\" && !Object.prototype.hasOwnProperty.call(this, name)) {\n Object.defineProperty(this, name, { value: descriptor.value.bind(this), writable: true, configurable: true });\n }\n }\n }\n }\n\n /** Same settings with another locale, e.g. when the user switches the interface language. */\n public withLocale(locale: string): LuxonAdapter {\n return new LuxonAdapter({ locale, timeZone: this.timeZone, formats: this._formatOverrides() });\n }\n\n private _formatOverrides(): Partial<DateFormatPatterns> {\n const overrides: Partial<DateFormatPatterns> = {};\n for (const key of Object.keys(DEFAULT_FORMATS) as DateFormatPattern[]) {\n if (this.formatPatterns[key] !== DEFAULT_FORMATS[key]) overrides[key] = this.formatPatterns[key];\n }\n return overrides;\n }\n\n private _resolve(formatOrPatternKey: string): string {\n return formatOrPatternKey in this.formatPatterns\n ? this.formatPatterns[formatOrPatternKey as DateFormatPattern]\n : formatOrPatternKey;\n }\n\n /** Luxon's zone option: the adapter's zone, else the runtime's. */\n private get _zone() {\n return this.timeZone ?? \"default\";\n }\n\n /**\n * A Luxon DateTime in the adapter's locale and time zone. Strings are read as ISO 8601,\n * in that zone when they have no offset.\n */\n private _dt(value: DateInput = new Date()): DateTime {\n const options = { zone: this._zone, locale: this.locale };\n return isString(value)\n ? DateTime.fromISO(value, options)\n : typeof value === \"number\"\n ? DateTime.fromMillis(value, options)\n : DateTime.fromJSDate(value, options);\n }\n\n private _isSame(left: DateInput, right: DateInput | undefined, unit: DateTimeUnit): boolean {\n return this._dt(left).hasSame(this._dt(right), unit);\n }\n\n public toMillis(date: DateInput): number {\n return this._dt(date).toMillis();\n }\n\n public fromMillis(millis: number): Date {\n return new Date(millis);\n }\n\n public format(\n date: DateInput,\n formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime\n ) {\n const value = this._dt(date);\n if (!value.isValid) throw new RangeError(\"Invalid time value\");\n return value.toFormat(this._resolve(formatOrPatternKey));\n }\n\n public formatDistanceToNow(date: DateInput) {\n return this._dt(date).toRelative() ?? \"\";\n }\n\n public tryFormat(\n date: DateInput,\n formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime\n ) {\n if (!this.isValid(date)) return null;\n return this.format(date, formatOrPatternKey);\n }\n\n public parse(\n dateString: string,\n formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime\n ): Date {\n return DateTime.fromFormat(dateString, this._resolve(formatOrPatternKey), {\n locale: this.locale,\n zone: this._zone,\n }).toJSDate();\n }\n\n public tryParse(\n dateString: string,\n formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime\n ) {\n const date = this.parse(dateString, formatOrPatternKey);\n return Number.isNaN(date.getTime()) ? null : date;\n }\n\n public parseISO(date: string): Date {\n return DateTime.fromISO(date, { zone: this._zone }).toJSDate();\n }\n\n public weekDayShortName(value: number): string {\n // 7 January 2024 is a Sunday: built in the adapter's zone, where a local midnight can be the day before\n return this.format(DateTime.fromObject({ year: 2024, month: 1, day: 7 + value, hour: 12 }, { zone: this._zone }).toJSDate(), \"weekdayShort\");\n }\n\n public monthShortName(value: DateInput): string {\n return this._dt(value).toFormat(\"LLL\");\n }\n\n public monthFullName(value: DateInput): string {\n return this._dt(value).toFormat(\"LLLL\");\n }\n\n // Get\n public getNow(date?: number | string): Date {\n return date ? new Date(date) : new Date();\n }\n\n public getEndOfMonth(date?: DateInput): Date {\n return this._dt(date).endOf(\"month\").toJSDate();\n }\n\n public getWeekDay(date?: DateInput) {\n return this._dt(date).weekday % 7;\n }\n\n public getMonthDay(date?: DateInput): number {\n return this._dt(date).day;\n }\n\n public getYears(date?: DateInput): number {\n return this._dt(date).year;\n }\n\n public getMonths(date?: DateInput) {\n // Luxon months are 1-based\n return this._dt(date).month - 1;\n }\n\n public getHours(date?: DateInput): number {\n return this._dt(date).hour;\n }\n\n public getMinutes(date?: DateInput): number {\n return this._dt(date).minute;\n }\n\n public getSeconds(date?: DateInput): number {\n return this._dt(date).second;\n }\n\n public getMilliseconds(date?: DateInput): number {\n return this._dt(date).millisecond;\n }\n\n public getToday(): Date {\n return this._dt().startOf(\"day\").toJSDate();\n }\n\n public getStartOfDay(date?: DateInput): Date {\n return this._dt(date).startOf(\"day\").toJSDate();\n }\n\n public getStartOfMonth(date?: DateInput): Date {\n return this._dt(date).startOf(\"month\").toJSDate();\n }\n\n public getStartOfWeek(date?: DateInput, weekStart: WeekDay = this.weekStartsOn): Date {\n const day = this._dt(date).startOf(\"day\");\n return day.minus({ days: ((day.weekday % 7) - weekStart + 7) % 7 }).toJSDate();\n }\n\n public getEndOfWeek(date?: DateInput, weekStart: WeekDay = this.weekStartsOn): Date {\n return this._dt(this.getStartOfWeek(date, weekStart))\n .plus({ days: 6 })\n .endOf(\"day\")\n .toJSDate();\n }\n\n public getStartOfYearPeriod(date?: DateInput, period = 0) {\n const yearStart = this._dt(date).startOf(\"year\");\n if (period) {\n return yearStart.set({ year: Math.floor(yearStart.year / period) * period }).toJSDate();\n }\n\n return yearStart.toJSDate();\n }\n\n public getDifferenceInMinutes(left: DateInput, right?: DateInput): number {\n return Math.trunc(this._dt(left).diff(this._dt(right), \"minutes\").minutes);\n }\n\n public addYears(date: DateInput, count: number): Date {\n return this._dt(date).plus({ years: count }).toJSDate();\n }\n\n public addMonths(date: DateInput, count: number): Date {\n return this._dt(date).plus({ months: count }).toJSDate();\n }\n\n public addDays(date: DateInput, count: number): Date {\n return this._dt(date).plus({ days: count }).toJSDate();\n }\n\n public addHours(date: DateInput, count: number): Date {\n return this._dt(date).plus({ hours: count }).toJSDate();\n }\n\n public addMinutes(date: DateInput, count: number): Date {\n return this._dt(date).plus({ minutes: count }).toJSDate();\n }\n\n public addSeconds(date: DateInput, count: number): Date {\n return this._dt(date).plus({ seconds: count }).toJSDate();\n }\n\n public setYears(date: DateInput, year: number): Date {\n return this._dt(date).set({ year }).toJSDate();\n }\n\n public setMonths(date: DateInput, month: number): Date {\n return this._dt(date).set({ month: month + 1 }).toJSDate();\n }\n\n public setMonthDay(date: DateInput, day: number): Date {\n return this._dt(date).set({ day }).toJSDate();\n }\n\n public setHours(date: DateInput, hour: number): Date {\n return this._dt(date).set({ hour }).toJSDate();\n }\n\n public setMinutes(date: DateInput, minute: number): Date {\n return this._dt(date).set({ minute }).toJSDate();\n }\n\n public setSeconds(date: DateInput, second: number): Date {\n return this._dt(date).set({ second }).toJSDate();\n }\n\n public setMilliseconds(date: DateInput, millisecond: number): Date {\n return this._dt(date).set({ millisecond }).toJSDate();\n }\n\n public isBefore(date1: DateInput, date2?: DateInput): boolean {\n return this._dt(date1) < this._dt(date2);\n }\n\n public isAfter(date1: DateInput, date2?: DateInput): boolean {\n return this._dt(date1) > this._dt(date2);\n }\n\n public isValid(date: DateInput): boolean {\n return this._dt(date).isValid;\n }\n\n public isMatch(\n date: string,\n formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime\n ): boolean {\n return DateTime.fromFormat(date, this._resolve(formatOrPatternKey), { locale: this.locale, zone: this._zone })\n .isValid;\n }\n\n public isToday(date: DateInput): boolean {\n return this._isSame(date, undefined, \"day\");\n }\n\n public isSameMonth(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"month\");\n }\n\n public isSameDay(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"day\");\n }\n\n public isSameYear(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"year\");\n }\n\n public isSameHour(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"hour\");\n }\n\n public isSameMinute(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"minute\");\n }\n\n public isSameSecond(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"second\");\n }\n\n public isDateInRange(\n date: DateInput,\n isSame: (left: DateInput, right: DateInput) => boolean,\n start?: DateInput,\n end?: DateInput\n ) {\n if (start && end) {\n return (\n isSame(date, start) ||\n isSame(date, end) ||\n (this.isAfter(date, start) && this.isBefore(date, end))\n );\n }\n return (start && isSame(date, start)) || (end && isSame(date, end)) || false;\n }\n\n public isSameDate(left: DateInput, right?: DateInput) {\n return this.isSameDay(left, right);\n }\n\n public isSameDateTime(left: DateInput, right?: DateInput) {\n return this.isSameSecond(left, right);\n }\n\n public isEqual(left: DateInput, right?: DateInput) {\n return this._dt(left).toMillis() === this._dt(right).toMillis();\n }\n}\n"],"mappings":"A,kJAoCA,IAAMK,EAAsC,CAC1C,OAAQ,KACR,YAAa,OACb,aAAc,MACd,UAAW,OACX,MAAO,MACP,cAAe,IACf,SAAU,IACV,aAAc,KACd,KAAM,IACN,SAAU,MACV,UAAW,SACX,KAAM,KACN,UAAW,IACX,YAAa,GACf,EAKqBC,EAArB,MAAqBA,CAAoC,CAMvD,YAAYC,EAA+B,CAAC,EAAG,CAC7C,KAAK,OAASA,EAAQ,QAAU,QAChC,KAAK,SAAWA,EA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jB,EAAMkB,CAAG,EAGjDD,GAASD,EAAOhB,EAAMiB,CAAK,GAAOC,GAAOF,EAAOhB,EAAMkB,CAAG,GAAM,EACzE,CAEO,WAAWrB,EAAiBC,EAAmB,CACpD,OAAO,KAAK,UAAUD,EAAMC,CAAK,CACnC,CAEO,eAAeD,EAAiBC,EAAmB,CACxD,OAAO,KAAK,aAAaD,EAAMC,CAAK,CACtC,CAEO,QAAQD,EAAiBC,EAAmB,CACjD,OAAO,KAAK,IAAID,CAAI,CAAC,CAAC,SAAS,IAAM,KAAK,IAAIC,CAAK,CAAC,CAAC,SAAS,CAChE,CACF,E"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["Info","isString","DateTime","luxon","_weekwise_core","DEFAULT_FORMATS","LuxonAdapter","options","proto","name","descriptor","locale","overrides","key","formatOrPatternKey","value","left","right","unit","date","millis","dateString","weekStart","day","period","yearStart","count","year","month","hour","minute","second","millisecond","date1","date2","isSame","start","end"],"sources":["../src/LuxonAdapter.ts"],"sourcesContent":["import { DateTime, Info, type DateTimeUnit } from \"luxon\";\n\nimport {\n isString,\n type DateAdapter,\n type DateFormatPattern,\n type DateFormatPatterns,\n type WeekDay,\n} from \"@weekwise/core\";\n\ntype DateInput = Date | number | string;\n\nexport interface LuxonAdapterOptions {\n /**\n * BCP 47 locale, e.g. `\"ru\"`, `\"en-US\"`: month and weekday names, date/time formats and the\n * first day of the week come from the browser's Intl data, so no locale files are imported.\n * The calendar picks its interface language by it too. Defaults to `\"en-GB\"`.\n *\n * @example\n * new LuxonAdapter({ locale: \"ru\" });\n */\n locale?: string;\n /**\n * IANA time zone the calendar shows, e.g. `\"America/New_York\"`: days start at its midnight\n * and times are its wall-clock times. Dates stay `Date`s (moments in time). Defaults to the\n * runtime's zone.\n */\n timeZone?: string;\n /** Overrides of the built-in patterns, in Luxon tokens: `{ timeShort: \"h:mm a\" }`. */\n formats?: Partial<DateFormatPatterns>;\n}\n\n/**\n * Built-in patterns. `D`/`DDD` (date), `t`/`tt` (time) and `f`/`F`/`ff` (date and time) are\n * Luxon macro tokens, so every locale gets its own order, separators and 12/24-hour clock.\n */\nconst DEFAULT_FORMATS: DateFormatPatterns = {\n dayNum: \"dd\",\n weekdayLong: \"cccc\",\n weekdayShort: \"ccc\",\n monthLong: \"LLLL\",\n month: \"LLL\",\n dateTimeShort: \"f\",\n dateTime: \"F\",\n dateTimeLong: \"ff\",\n date: \"D\",\n dateLong: \"DDD\",\n dateShort: \"d MMMM\",\n time: \"tt\",\n timeShort: \"t\",\n timeCompact: \"t\",\n};\n\n/**\n * {@link DateAdapter} implementation backed by Luxon.\n */\nexport default class LuxonAdapter implements DateAdapter {\n readonly locale: string;\n readonly weekStartsOn: WeekDay;\n readonly timeZone?: string;\n readonly formatPatterns: DateFormatPatterns;\n\n constructor(options: LuxonAdapterOptions = {}) {\n this.locale = options.locale ?? \"en-GB\";\n this.timeZone = options.timeZone;\n // Luxon numbers weekdays 1 (Monday) … 7 (Sunday)\n this.weekStartsOn = (Info.getStartOfWeek({ locale: this.locale }) % 7) as WeekDay;\n this.formatPatterns = { ...DEFAULT_FORMATS, ...options.formats };\n\n // The calendar destructures adapter methods (`const { format } = adapter`)\n for (\n let proto = Object.getPrototypeOf(this);\n proto && proto !== Object.prototype;\n proto = Object.getPrototypeOf(proto)\n ) {\n for (const name of Object.getOwnPropertyNames(proto)) {\n const descriptor = Object.getOwnPropertyDescriptor(proto, name);\n if (\n name !== \"constructor\" &&\n typeof descriptor?.value === \"function\" &&\n !Object.prototype.hasOwnProperty.call(this, name)\n ) {\n Object.defineProperty(this, name, { value: descriptor.value.bind(this), writable: true, configurable: true });\n }\n }\n }\n }\n\n /** Same settings with another locale, e.g. when the user switches the interface language. */\n public withLocale(locale: string): LuxonAdapter {\n return new LuxonAdapter({ locale, timeZone: this.timeZone, formats: this._formatOverrides() });\n }\n\n private _formatOverrides(): Partial<DateFormatPatterns> {\n const overrides: Partial<DateFormatPatterns> = {};\n for (const key of Object.keys(DEFAULT_FORMATS) as DateFormatPattern[]) {\n if (this.formatPatterns[key] !== DEFAULT_FORMATS[key]) overrides[key] = this.formatPatterns[key];\n }\n return overrides;\n }\n\n private _resolve(formatOrPatternKey: string): string {\n return formatOrPatternKey in this.formatPatterns\n ? this.formatPatterns[formatOrPatternKey as DateFormatPattern]\n : formatOrPatternKey;\n }\n\n /** Luxon's zone option: the adapter's zone, else the runtime's. */\n private get _zone() {\n return this.timeZone ?? \"default\";\n }\n\n /**\n * A Luxon DateTime in the adapter's locale and time zone. Strings are read as ISO 8601,\n * in that zone when they have no offset.\n */\n private _dt(value: DateInput = new Date()): DateTime {\n const options = { zone: this._zone, locale: this.locale };\n return isString(value)\n ? DateTime.fromISO(value, options)\n : typeof value === \"number\"\n ? DateTime.fromMillis(value, options)\n : DateTime.fromJSDate(value, options);\n }\n\n private _isSame(left: DateInput, right: DateInput | undefined, unit: DateTimeUnit): boolean {\n return this._dt(left).hasSame(this._dt(right), unit);\n }\n\n public toMillis(date: DateInput): number {\n return this._dt(date).toMillis();\n }\n\n public fromMillis(millis: number): Date {\n return new Date(millis);\n }\n\n public format(date: DateInput, formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime) {\n const value = this._dt(date);\n if (!value.isValid) throw new RangeError(\"Invalid time value\");\n return value.toFormat(this._resolve(formatOrPatternKey));\n }\n\n public formatDistanceToNow(date: DateInput) {\n return this._dt(date).toRelative() ?? \"\";\n }\n\n public tryFormat(\n date: DateInput,\n formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime\n ) {\n if (!this.isValid(date)) return null;\n return this.format(date, formatOrPatternKey);\n }\n\n public parse(\n dateString: string,\n formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime\n ): Date {\n return DateTime.fromFormat(dateString, this._resolve(formatOrPatternKey), {\n locale: this.locale,\n zone: this._zone,\n }).toJSDate();\n }\n\n public tryParse(\n dateString: string,\n formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime\n ) {\n const date = this.parse(dateString, formatOrPatternKey);\n return Number.isNaN(date.getTime()) ? null : date;\n }\n\n public parseISO(date: string): Date {\n return DateTime.fromISO(date, { zone: this._zone }).toJSDate();\n }\n\n public weekDayShortName(value: number): string {\n // 7 January 2024 is a Sunday: built in the adapter's zone, where a local midnight can be the day before\n return this.format(\n DateTime.fromObject({ year: 2024, month: 1, day: 7 + value, hour: 12 }, { zone: this._zone }).toJSDate(),\n \"weekdayShort\"\n );\n }\n\n public monthShortName(value: DateInput): string {\n return this._dt(value).toFormat(\"LLL\");\n }\n\n public monthFullName(value: DateInput): string {\n return this._dt(value).toFormat(\"LLLL\");\n }\n\n // Get\n public getNow(date?: number | string): Date {\n return date ? new Date(date) : new Date();\n }\n\n public getEndOfMonth(date?: DateInput): Date {\n return this._dt(date).endOf(\"month\").toJSDate();\n }\n\n public getWeekDay(date?: DateInput) {\n return this._dt(date).weekday % 7;\n }\n\n public getMonthDay(date?: DateInput): number {\n return this._dt(date).day;\n }\n\n public getYears(date?: DateInput): number {\n return this._dt(date).year;\n }\n\n public getMonths(date?: DateInput) {\n // Luxon months are 1-based\n return this._dt(date).month - 1;\n }\n\n public getHours(date?: DateInput): number {\n return this._dt(date).hour;\n }\n\n public getMinutes(date?: DateInput): number {\n return this._dt(date).minute;\n }\n\n public getSeconds(date?: DateInput): number {\n return this._dt(date).second;\n }\n\n public getMilliseconds(date?: DateInput): number {\n return this._dt(date).millisecond;\n }\n\n public getToday(): Date {\n return this._dt().startOf(\"day\").toJSDate();\n }\n\n public getStartOfDay(date?: DateInput): Date {\n return this._dt(date).startOf(\"day\").toJSDate();\n }\n\n public getStartOfMonth(date?: DateInput): Date {\n return this._dt(date).startOf(\"month\").toJSDate();\n }\n\n public getStartOfWeek(date?: DateInput, weekStart: WeekDay = this.weekStartsOn): Date {\n const day = this._dt(date).startOf(\"day\");\n return day.minus({ days: ((day.weekday % 7) - weekStart + 7) % 7 }).toJSDate();\n }\n\n public getEndOfWeek(date?: DateInput, weekStart: WeekDay = this.weekStartsOn): Date {\n return this._dt(this.getStartOfWeek(date, weekStart)).plus({ days: 6 }).endOf(\"day\").toJSDate();\n }\n\n public getStartOfYearPeriod(date?: DateInput, period = 0) {\n const yearStart = this._dt(date).startOf(\"year\");\n if (period) {\n return yearStart.set({ year: Math.floor(yearStart.year / period) * period }).toJSDate();\n }\n\n return yearStart.toJSDate();\n }\n\n public getDifferenceInMinutes(left: DateInput, right?: DateInput): number {\n return Math.trunc(this._dt(left).diff(this._dt(right), \"minutes\").minutes);\n }\n\n public addYears(date: DateInput, count: number): Date {\n return this._dt(date).plus({ years: count }).toJSDate();\n }\n\n public addMonths(date: DateInput, count: number): Date {\n return this._dt(date).plus({ months: count }).toJSDate();\n }\n\n public addDays(date: DateInput, count: number): Date {\n return this._dt(date).plus({ days: count }).toJSDate();\n }\n\n public addHours(date: DateInput, count: number): Date {\n return this._dt(date).plus({ hours: count }).toJSDate();\n }\n\n public addMinutes(date: DateInput, count: number): Date {\n return this._dt(date).plus({ minutes: count }).toJSDate();\n }\n\n public addSeconds(date: DateInput, count: number): Date {\n return this._dt(date).plus({ seconds: count }).toJSDate();\n }\n\n public setYears(date: DateInput, year: number): Date {\n return this._dt(date).set({ year }).toJSDate();\n }\n\n public setMonths(date: DateInput, month: number): Date {\n return this._dt(date)\n .set({ month: month + 1 })\n .toJSDate();\n }\n\n public setMonthDay(date: DateInput, day: number): Date {\n return this._dt(date).set({ day }).toJSDate();\n }\n\n public setHours(date: DateInput, hour: number): Date {\n return this._dt(date).set({ hour }).toJSDate();\n }\n\n public setMinutes(date: DateInput, minute: number): Date {\n return this._dt(date).set({ minute }).toJSDate();\n }\n\n public setSeconds(date: DateInput, second: number): Date {\n return this._dt(date).set({ second }).toJSDate();\n }\n\n public setMilliseconds(date: DateInput, millisecond: number): Date {\n return this._dt(date).set({ millisecond }).toJSDate();\n }\n\n public isBefore(date1: DateInput, date2?: DateInput): boolean {\n return this._dt(date1) < this._dt(date2);\n }\n\n public isAfter(date1: DateInput, date2?: DateInput): boolean {\n return this._dt(date1) > this._dt(date2);\n }\n\n public isValid(date: DateInput): boolean {\n return this._dt(date).isValid;\n }\n\n public isMatch(\n date: string,\n formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime\n ): boolean {\n return DateTime.fromFormat(date, this._resolve(formatOrPatternKey), { locale: this.locale, zone: this._zone })\n .isValid;\n }\n\n public isToday(date: DateInput): boolean {\n return this._isSame(date, undefined, \"day\");\n }\n\n public isSameMonth(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"month\");\n }\n\n public isSameDay(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"day\");\n }\n\n public isSameYear(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"year\");\n }\n\n public isSameHour(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"hour\");\n }\n\n public isSameMinute(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"minute\");\n }\n\n public isSameSecond(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"second\");\n }\n\n public isDateInRange(\n date: DateInput,\n isSame: (left: DateInput, right: DateInput) => boolean,\n start?: DateInput,\n end?: DateInput\n ) {\n if (start && end) {\n return isSame(date, start) || isSame(date, end) || (this.isAfter(date, start) && this.isBefore(date, end));\n }\n return (start && isSame(date, start)) || (end && isSame(date, end)) || false;\n }\n\n public isSameDate(left: DateInput, right?: DateInput) {\n return this.isSameDay(left, right);\n }\n\n public isSameDateTime(left: DateInput, right?: DateInput) {\n return this.isSameSecond(left, right);\n }\n\n public isEqual(left: DateInput, right?: DateInput) {\n return this._dt(left).toMillis() === this._dt(right).toMillis();\n }\n}\n"],"mappings":"A,kJAoCA,IAAMK,EAAsC,CAC1C,OAAQ,KACR,YAAa,OACb,aAAc,MACd,UAAW,OACX,MAAO,MACP,cAAe,IACf,SAAU,IACV,aAAc,KACd,KAAM,IACN,SAAU,MACV,UAAW,SACX,KAAM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,EACAC,EACAC,EACA,CAIA,OAHID,GAASC,EACJF,EAAOhB,EAAMiB,CAAK,GAAKD,EAAOhB,EAAMkB,CAAG,GAAM,KAAK,QAAQlB,EAAMiB,CAAK,GAAK,KAAK,SAASjB,EAAMkB,CAAG,EAElGD,GAASD,EAAOhB,EAAMiB,CAAK,GAAOC,GAAOF,EAAOhB,EAAMkB,CAAG,GAAM,EACzE,CAEO,WAAWrB,EAAiBC,EAAmB,CACpD,OAAO,KAAK,UAAUD,EAAMC,CAAK,CACnC,CAEO,eAAeD,EAAiBC,EAAmB,CACxD,OAAO,KAAK,aAAaD,EAAMC,CAAK,CACtC,CAEO,QAAQD,EAAiBC,EAAmB,CACjD,OAAO,KAAK,IAAID,CAAI,CAAC,CAAC,SAAS,IAAM,KAAK,IAAIC,CAAK,CAAC,CAAC,SAAS,CAChE,CACF,E"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["DateTime","Info","isString","DEFAULT_FORMATS","LuxonAdapter","options","proto","name","descriptor","locale","overrides","key","formatOrPatternKey","value","left","right","unit","date","millis","dateString","weekStart","day","period","yearStart","count","year","month","hour","minute","second","millisecond","date1","date2","isSame","start","end"],"sources":["../src/LuxonAdapter.ts"],"sourcesContent":["import { DateTime, Info, type DateTimeUnit } from \"luxon\";\n\nimport {\n isString,\n type DateAdapter,\n type DateFormatPattern,\n type DateFormatPatterns,\n type WeekDay,\n} from \"@weekwise/core\";\n\ntype DateInput = Date | number | string;\n\nexport interface LuxonAdapterOptions {\n /**\n * BCP 47 locale, e.g. `\"ru\"`, `\"en-US\"`: month and weekday names, date/time formats and the\n * first day of the week come from the browser's Intl data, so no locale files are imported.\n * The calendar picks its interface language by it too. Defaults to `\"en-GB\"`.\n *\n * @example\n * new LuxonAdapter({ locale: \"ru\" });\n */\n locale?: string;\n /**\n * IANA time zone the calendar shows, e.g. `\"America/New_York\"`: days start at its midnight\n * and times are its wall-clock times. Dates stay `Date`s (moments in time). Defaults to the\n * runtime's zone.\n */\n timeZone?: string;\n /** Overrides of the built-in patterns, in Luxon tokens: `{ timeShort: \"h:mm a\" }`. */\n formats?: Partial<DateFormatPatterns>;\n}\n\n/**\n * Built-in patterns. `D`/`DDD` (date), `t`/`tt` (time) and `f`/`F`/`ff` (date and time) are\n * Luxon macro tokens, so every locale gets its own order, separators and 12/24-hour clock.\n */\nconst DEFAULT_FORMATS: DateFormatPatterns = {\n dayNum: \"dd\",\n weekdayLong: \"cccc\",\n weekdayShort: \"ccc\",\n monthLong: \"LLLL\",\n month: \"LLL\",\n dateTimeShort: \"f\",\n dateTime: \"F\",\n dateTimeLong: \"ff\",\n date: \"D\",\n dateLong: \"DDD\",\n dateShort: \"d MMMM\",\n time: \"tt\",\n timeShort: \"t\",\n timeCompact: \"t\",\n};\n\n/**\n * {@link DateAdapter} implementation backed by Luxon.\n */\nexport default class LuxonAdapter implements DateAdapter {\n readonly locale: string;\n readonly weekStartsOn: WeekDay;\n readonly timeZone?: string;\n readonly formatPatterns: DateFormatPatterns;\n\n constructor(options: LuxonAdapterOptions = {}) {\n this.locale = options.locale ?? \"en-GB\";\n this.timeZone = options.timeZone;\n // Luxon numbers weekdays 1 (Monday) … 7 (Sunday)\n this.weekStartsOn = (Info.getStartOfWeek({ locale: this.locale }) % 7) as WeekDay;\n this.formatPatterns = { ...DEFAULT_FORMATS, ...options.formats };\n\n // The calendar destructures adapter methods (`const { format } = adapter`)\n for (let proto = Object.getPrototypeOf(this); proto && proto !== Object.prototype; proto = Object.getPrototypeOf(proto)) {\n for (const name of Object.getOwnPropertyNames(proto)) {\n const descriptor = Object.getOwnPropertyDescriptor(proto, name);\n if (name !== \"constructor\" && typeof descriptor?.value === \"function\" && !Object.prototype.hasOwnProperty.call(this, name)) {\n Object.defineProperty(this, name, { value: descriptor.value.bind(this), writable: true, configurable: true });\n }\n }\n }\n }\n\n /** Same settings with another locale, e.g. when the user switches the interface language. */\n public withLocale(locale: string): LuxonAdapter {\n return new LuxonAdapter({ locale, timeZone: this.timeZone, formats: this._formatOverrides() });\n }\n\n private _formatOverrides(): Partial<DateFormatPatterns> {\n const overrides: Partial<DateFormatPatterns> = {};\n for (const key of Object.keys(DEFAULT_FORMATS) as DateFormatPattern[]) {\n if (this.formatPatterns[key] !== DEFAULT_FORMATS[key]) overrides[key] = this.formatPatterns[key];\n }\n return overrides;\n }\n\n private _resolve(formatOrPatternKey: string): string {\n return formatOrPatternKey in this.formatPatterns\n ? this.formatPatterns[formatOrPatternKey as DateFormatPattern]\n : formatOrPatternKey;\n }\n\n /** Luxon's zone option: the adapter's zone, else the runtime's. */\n private get _zone() {\n return this.timeZone ?? \"default\";\n }\n\n /**\n * A Luxon DateTime in the adapter's locale and time zone. Strings are read as ISO 8601,\n * in that zone when they have no offset.\n */\n private _dt(value: DateInput = new Date()): DateTime {\n const options = { zone: this._zone, locale: this.locale };\n return isString(value)\n ? DateTime.fromISO(value, options)\n : typeof value === \"number\"\n ? DateTime.fromMillis(value, options)\n : DateTime.fromJSDate(value, options);\n }\n\n private _isSame(left: DateInput, right: DateInput | undefined, unit: DateTimeUnit): boolean {\n return this._dt(left).hasSame(this._dt(right), unit);\n }\n\n public toMillis(date: DateInput): number {\n return this._dt(date).toMillis();\n }\n\n public fromMillis(millis: number): Date {\n return new Date(millis);\n }\n\n public format(\n date: DateInput,\n formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime\n ) {\n const value = this._dt(date);\n if (!value.isValid) throw new RangeError(\"Invalid time value\");\n return value.toFormat(this._resolve(formatOrPatternKey));\n }\n\n public formatDistanceToNow(date: DateInput) {\n return this._dt(date).toRelative() ?? \"\";\n }\n\n public tryFormat(\n date: DateInput,\n formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime\n ) {\n if (!this.isValid(date)) return null;\n return this.format(date, formatOrPatternKey);\n }\n\n public parse(\n dateString: string,\n formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime\n ): Date {\n return DateTime.fromFormat(dateString, this._resolve(formatOrPatternKey), {\n locale: this.locale,\n zone: this._zone,\n }).toJSDate();\n }\n\n public tryParse(\n dateString: string,\n formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime\n ) {\n const date = this.parse(dateString, formatOrPatternKey);\n return Number.isNaN(date.getTime()) ? null : date;\n }\n\n public parseISO(date: string): Date {\n return DateTime.fromISO(date, { zone: this._zone }).toJSDate();\n }\n\n public weekDayShortName(value: number): string {\n // 7 January 2024 is a Sunday: built in the adapter's zone, where a local midnight can be the day before\n return this.format(DateTime.fromObject({ year: 2024, month: 1, day: 7 + value, hour: 12 }, { zone: this._zone }).toJSDate(), \"weekdayShort\");\n }\n\n public monthShortName(value: DateInput): string {\n return this._dt(value).toFormat(\"LLL\");\n }\n\n public monthFullName(value: DateInput): string {\n return this._dt(value).toFormat(\"LLLL\");\n }\n\n // Get\n public getNow(date?: number | string): Date {\n return date ? new Date(date) : new Date();\n }\n\n public getEndOfMonth(date?: DateInput): Date {\n return this._dt(date).endOf(\"month\").toJSDate();\n }\n\n public getWeekDay(date?: DateInput) {\n return this._dt(date).weekday % 7;\n }\n\n public getMonthDay(date?: DateInput): number {\n return this._dt(date).day;\n }\n\n public getYears(date?: DateInput): number {\n return this._dt(date).year;\n }\n\n public getMonths(date?: DateInput) {\n // Luxon months are 1-based\n return this._dt(date).month - 1;\n }\n\n public getHours(date?: DateInput): number {\n return this._dt(date).hour;\n }\n\n public getMinutes(date?: DateInput): number {\n return this._dt(date).minute;\n }\n\n public getSeconds(date?: DateInput): number {\n return this._dt(date).second;\n }\n\n public getMilliseconds(date?: DateInput): number {\n return this._dt(date).millisecond;\n }\n\n public getToday(): Date {\n return this._dt().startOf(\"day\").toJSDate();\n }\n\n public getStartOfDay(date?: DateInput): Date {\n return this._dt(date).startOf(\"day\").toJSDate();\n }\n\n public getStartOfMonth(date?: DateInput): Date {\n return this._dt(date).startOf(\"month\").toJSDate();\n }\n\n public getStartOfWeek(date?: DateInput, weekStart: WeekDay = this.weekStartsOn): Date {\n const day = this._dt(date).startOf(\"day\");\n return day.minus({ days: ((day.weekday % 7) - weekStart + 7) % 7 }).toJSDate();\n }\n\n public getEndOfWeek(date?: DateInput, weekStart: WeekDay = this.weekStartsOn): Date {\n return this._dt(this.getStartOfWeek(date, weekStart))\n .plus({ days: 6 })\n .endOf(\"day\")\n .toJSDate();\n }\n\n public getStartOfYearPeriod(date?: DateInput, period = 0) {\n const yearStart = this._dt(date).startOf(\"year\");\n if (period) {\n return yearStart.set({ year: Math.floor(yearStart.year / period) * period }).toJSDate();\n }\n\n return yearStart.toJSDate();\n }\n\n public getDifferenceInMinutes(left: DateInput, right?: DateInput): number {\n return Math.trunc(this._dt(left).diff(this._dt(right), \"minutes\").minutes);\n }\n\n public addYears(date: DateInput, count: number): Date {\n return this._dt(date).plus({ years: count }).toJSDate();\n }\n\n public addMonths(date: DateInput, count: number): Date {\n return this._dt(date).plus({ months: count }).toJSDate();\n }\n\n public addDays(date: DateInput, count: number): Date {\n return this._dt(date).plus({ days: count }).toJSDate();\n }\n\n public addHours(date: DateInput, count: number): Date {\n return this._dt(date).plus({ hours: count }).toJSDate();\n }\n\n public addMinutes(date: DateInput, count: number): Date {\n return this._dt(date).plus({ minutes: count }).toJSDate();\n }\n\n public addSeconds(date: DateInput, count: number): Date {\n return this._dt(date).plus({ seconds: count }).toJSDate();\n }\n\n public setYears(date: DateInput, year: number): Date {\n return this._dt(date).set({ year }).toJSDate();\n }\n\n public setMonths(date: DateInput, month: number): Date {\n return this._dt(date).set({ month: month + 1 }).toJSDate();\n }\n\n public setMonthDay(date: DateInput, day: number): Date {\n return this._dt(date).set({ day }).toJSDate();\n }\n\n public setHours(date: DateInput, hour: number): Date {\n return this._dt(date).set({ hour }).toJSDate();\n }\n\n public setMinutes(date: DateInput, minute: number): Date {\n return this._dt(date).set({ minute }).toJSDate();\n }\n\n public setSeconds(date: DateInput, second: number): Date {\n return this._dt(date).set({ second }).toJSDate();\n }\n\n public setMilliseconds(date: DateInput, millisecond: number): Date {\n return this._dt(date).set({ millisecond }).toJSDate();\n }\n\n public isBefore(date1: DateInput, date2?: DateInput): boolean {\n return this._dt(date1) < this._dt(date2);\n }\n\n public isAfter(date1: DateInput, date2?: DateInput): boolean {\n return this._dt(date1) > this._dt(date2);\n }\n\n public isValid(date: DateInput): boolean {\n return this._dt(date).isValid;\n }\n\n public isMatch(\n date: string,\n formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime\n ): boolean {\n return DateTime.fromFormat(date, this._resolve(formatOrPatternKey), { locale: this.locale, zone: this._zone })\n .isValid;\n }\n\n public isToday(date: DateInput): boolean {\n return this._isSame(date, undefined, \"day\");\n }\n\n public isSameMonth(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"month\");\n }\n\n public isSameDay(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"day\");\n }\n\n public isSameYear(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"year\");\n }\n\n public isSameHour(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"hour\");\n }\n\n public isSameMinute(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"minute\");\n }\n\n public isSameSecond(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"second\");\n }\n\n public isDateInRange(\n date: DateInput,\n isSame: (left: DateInput, right: DateInput) => boolean,\n start?: DateInput,\n end?: DateInput\n ) {\n if (start && end) {\n return (\n isSame(date, start) ||\n isSame(date, end) ||\n (this.isAfter(date, start) && this.isBefore(date, end))\n );\n }\n return (start && isSame(date, start)) || (end && isSame(date, end)) || false;\n }\n\n public isSameDate(left: DateInput, right?: DateInput) {\n return this.isSameDay(left, right);\n }\n\n public isSameDateTime(left: DateInput, right?: DateInput) {\n return this.isSameSecond(left, right);\n }\n\n public isEqual(left: DateInput, right?: DateInput) {\n return this._dt(left).toMillis() === this._dt(right).toMillis();\n }\n}\n"],"m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3C;CAEO,aAAaD,GAAiBC,GAA4B;EAC/D,OAAO,KAAK,QAAQD,GAAMC,GAAO,QAAQ;CAC3C;CAEO,cACLE,GACAgB,GACAC,GACAC,GACA;EAQA,OAPID,KAASC,IAETF,EAAOhB,GAAMiB,CAAK,KAClBD,EAAOhB,GAAMkB,CAAG,KACf,KAAK,QAAQlB,GAAMiB,CAAK,KAAK,KAAK,SAASjB,GAAMkB,CAAG,IAGjDD,KAASD,EAAOhB,GAAMiB,CAAK,KAAOC,KAAOF,EAAOhB,GAAMkB,CAAG,KAAM;CACzE;CAEO,WAAWrB,GAAiBC,GAAmB;EACpD,OAAO,KAAK,UAAUD,GAAMC,CAAK;CACnC;CAEO,eAAeD,GAAiBC,GAAmB;EACxD,OAAO,KAAK,aAAaD,GAAMC,CAAK;CACtC;CAEO,QAAQD,GAAiBC,GAAmB;EACjD,OAAO,KAAK,IAAID,CAAI,CAAC,CAAC,SAAS,MAAM,KAAK,IAAIC,CAAK,CAAC,CAAC,SAAS;CAChE;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["DateTime","Info","isString","DEFAULT_FORMATS","LuxonAdapter","options","proto","name","descriptor","locale","overrides","key","formatOrPatternKey","value","left","right","unit","date","millis","dateString","weekStart","day","period","yearStart","count","year","month","hour","minute","second","millisecond","date1","date2","isSame","start","end"],"sources":["../src/LuxonAdapter.ts"],"sourcesContent":["import { DateTime, Info, type DateTimeUnit } from \"luxon\";\n\nimport {\n isString,\n type DateAdapter,\n type DateFormatPattern,\n type DateFormatPatterns,\n type WeekDay,\n} from \"@weekwise/core\";\n\ntype DateInput = Date | number | string;\n\nexport interface LuxonAdapterOptions {\n /**\n * BCP 47 locale, e.g. `\"ru\"`, `\"en-US\"`: month and weekday names, date/time formats and the\n * first day of the week come from the browser's Intl data, so no locale files are imported.\n * The calendar picks its interface language by it too. Defaults to `\"en-GB\"`.\n *\n * @example\n * new LuxonAdapter({ locale: \"ru\" });\n */\n locale?: string;\n /**\n * IANA time zone the calendar shows, e.g. `\"America/New_York\"`: days start at its midnight\n * and times are its wall-clock times. Dates stay `Date`s (moments in time). Defaults to the\n * runtime's zone.\n */\n timeZone?: string;\n /** Overrides of the built-in patterns, in Luxon tokens: `{ timeShort: \"h:mm a\" }`. */\n formats?: Partial<DateFormatPatterns>;\n}\n\n/**\n * Built-in patterns. `D`/`DDD` (date), `t`/`tt` (time) and `f`/`F`/`ff` (date and time) are\n * Luxon macro tokens, so every locale gets its own order, separators and 12/24-hour clock.\n */\nconst DEFAULT_FORMATS: DateFormatPatterns = {\n dayNum: \"dd\",\n weekdayLong: \"cccc\",\n weekdayShort: \"ccc\",\n monthLong: \"LLLL\",\n month: \"LLL\",\n dateTimeShort: \"f\",\n dateTime: \"F\",\n dateTimeLong: \"ff\",\n date: \"D\",\n dateLong: \"DDD\",\n dateShort: \"d MMMM\",\n time: \"tt\",\n timeShort: \"t\",\n timeCompact: \"t\",\n};\n\n/**\n * {@link DateAdapter} implementation backed by Luxon.\n */\nexport default class LuxonAdapter implements DateAdapter {\n readonly locale: string;\n readonly weekStartsOn: WeekDay;\n readonly timeZone?: string;\n readonly formatPatterns: DateFormatPatterns;\n\n constructor(options: LuxonAdapterOptions = {}) {\n this.locale = options.locale ?? \"en-GB\";\n this.timeZone = options.timeZone;\n // Luxon numbers weekdays 1 (Monday) … 7 (Sunday)\n this.weekStartsOn = (Info.getStartOfWeek({ locale: this.locale }) % 7) as WeekDay;\n this.formatPatterns = { ...DEFAULT_FORMATS, ...options.formats };\n\n // The calendar destructures adapter methods (`const { format } = adapter`)\n for (\n let proto = Object.getPrototypeOf(this);\n proto && proto !== Object.prototype;\n proto = Object.getPrototypeOf(proto)\n ) {\n for (const name of Object.getOwnPropertyNames(proto)) {\n const descriptor = Object.getOwnPropertyDescriptor(proto, name);\n if (\n name !== \"constructor\" &&\n typeof descriptor?.value === \"function\" &&\n !Object.prototype.hasOwnProperty.call(this, name)\n ) {\n Object.defineProperty(this, name, { value: descriptor.value.bind(this), writable: true, configurable: true });\n }\n }\n }\n }\n\n /** Same settings with another locale, e.g. when the user switches the interface language. */\n public withLocale(locale: string): LuxonAdapter {\n return new LuxonAdapter({ locale, timeZone: this.timeZone, formats: this._formatOverrides() });\n }\n\n private _formatOverrides(): Partial<DateFormatPatterns> {\n const overrides: Partial<DateFormatPatterns> = {};\n for (const key of Object.keys(DEFAULT_FORMATS) as DateFormatPattern[]) {\n if (this.formatPatterns[key] !== DEFAULT_FORMATS[key]) overrides[key] = this.formatPatterns[key];\n }\n return overrides;\n }\n\n private _resolve(formatOrPatternKey: string): string {\n return formatOrPatternKey in this.formatPatterns\n ? this.formatPatterns[formatOrPatternKey as DateFormatPattern]\n : formatOrPatternKey;\n }\n\n /** Luxon's zone option: the adapter's zone, else the runtime's. */\n private get _zone() {\n return this.timeZone ?? \"default\";\n }\n\n /**\n * A Luxon DateTime in the adapter's locale and time zone. Strings are read as ISO 8601,\n * in that zone when they have no offset.\n */\n private _dt(value: DateInput = new Date()): DateTime {\n const options = { zone: this._zone, locale: this.locale };\n return isString(value)\n ? DateTime.fromISO(value, options)\n : typeof value === \"number\"\n ? DateTime.fromMillis(value, options)\n : DateTime.fromJSDate(value, options);\n }\n\n private _isSame(left: DateInput, right: DateInput | undefined, unit: DateTimeUnit): boolean {\n return this._dt(left).hasSame(this._dt(right), unit);\n }\n\n public toMillis(date: DateInput): number {\n return this._dt(date).toMillis();\n }\n\n public fromMillis(millis: number): Date {\n return new Date(millis);\n }\n\n public format(date: DateInput, formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime) {\n const value = this._dt(date);\n if (!value.isValid) throw new RangeError(\"Invalid time value\");\n return value.toFormat(this._resolve(formatOrPatternKey));\n }\n\n public formatDistanceToNow(date: DateInput) {\n return this._dt(date).toRelative() ?? \"\";\n }\n\n public tryFormat(\n date: DateInput,\n formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime\n ) {\n if (!this.isValid(date)) return null;\n return this.format(date, formatOrPatternKey);\n }\n\n public parse(\n dateString: string,\n formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime\n ): Date {\n return DateTime.fromFormat(dateString, this._resolve(formatOrPatternKey), {\n locale: this.locale,\n zone: this._zone,\n }).toJSDate();\n }\n\n public tryParse(\n dateString: string,\n formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime\n ) {\n const date = this.parse(dateString, formatOrPatternKey);\n return Number.isNaN(date.getTime()) ? null : date;\n }\n\n public parseISO(date: string): Date {\n return DateTime.fromISO(date, { zone: this._zone }).toJSDate();\n }\n\n public weekDayShortName(value: number): string {\n // 7 January 2024 is a Sunday: built in the adapter's zone, where a local midnight can be the day before\n return this.format(\n DateTime.fromObject({ year: 2024, month: 1, day: 7 + value, hour: 12 }, { zone: this._zone }).toJSDate(),\n \"weekdayShort\"\n );\n }\n\n public monthShortName(value: DateInput): string {\n return this._dt(value).toFormat(\"LLL\");\n }\n\n public monthFullName(value: DateInput): string {\n return this._dt(value).toFormat(\"LLLL\");\n }\n\n // Get\n public getNow(date?: number | string): Date {\n return date ? new Date(date) : new Date();\n }\n\n public getEndOfMonth(date?: DateInput): Date {\n return this._dt(date).endOf(\"month\").toJSDate();\n }\n\n public getWeekDay(date?: DateInput) {\n return this._dt(date).weekday % 7;\n }\n\n public getMonthDay(date?: DateInput): number {\n return this._dt(date).day;\n }\n\n public getYears(date?: DateInput): number {\n return this._dt(date).year;\n }\n\n public getMonths(date?: DateInput) {\n // Luxon months are 1-based\n return this._dt(date).month - 1;\n }\n\n public getHours(date?: DateInput): number {\n return this._dt(date).hour;\n }\n\n public getMinutes(date?: DateInput): number {\n return this._dt(date).minute;\n }\n\n public getSeconds(date?: DateInput): number {\n return this._dt(date).second;\n }\n\n public getMilliseconds(date?: DateInput): number {\n return this._dt(date).millisecond;\n }\n\n public getToday(): Date {\n return this._dt().startOf(\"day\").toJSDate();\n }\n\n public getStartOfDay(date?: DateInput): Date {\n return this._dt(date).startOf(\"day\").toJSDate();\n }\n\n public getStartOfMonth(date?: DateInput): Date {\n return this._dt(date).startOf(\"month\").toJSDate();\n }\n\n public getStartOfWeek(date?: DateInput, weekStart: WeekDay = this.weekStartsOn): Date {\n const day = this._dt(date).startOf(\"day\");\n return day.minus({ days: ((day.weekday % 7) - weekStart + 7) % 7 }).toJSDate();\n }\n\n public getEndOfWeek(date?: DateInput, weekStart: WeekDay = this.weekStartsOn): Date {\n return this._dt(this.getStartOfWeek(date, weekStart)).plus({ days: 6 }).endOf(\"day\").toJSDate();\n }\n\n public getStartOfYearPeriod(date?: DateInput, period = 0) {\n const yearStart = this._dt(date).startOf(\"year\");\n if (period) {\n return yearStart.set({ year: Math.floor(yearStart.year / period) * period }).toJSDate();\n }\n\n return yearStart.toJSDate();\n }\n\n public getDifferenceInMinutes(left: DateInput, right?: DateInput): number {\n return Math.trunc(this._dt(left).diff(this._dt(right), \"minutes\").minutes);\n }\n\n public addYears(date: DateInput, count: number): Date {\n return this._dt(date).plus({ years: count }).toJSDate();\n }\n\n public addMonths(date: DateInput, count: number): Date {\n return this._dt(date).plus({ months: count }).toJSDate();\n }\n\n public addDays(date: DateInput, count: number): Date {\n return this._dt(date).plus({ days: count }).toJSDate();\n }\n\n public addHours(date: DateInput, count: number): Date {\n return this._dt(date).plus({ hours: count }).toJSDate();\n }\n\n public addMinutes(date: DateInput, count: number): Date {\n return this._dt(date).plus({ minutes: count }).toJSDate();\n }\n\n public addSeconds(date: DateInput, count: number): Date {\n return this._dt(date).plus({ seconds: count }).toJSDate();\n }\n\n public setYears(date: DateInput, year: number): Date {\n return this._dt(date).set({ year }).toJSDate();\n }\n\n public setMonths(date: DateInput, month: number): Date {\n return this._dt(date)\n .set({ month: month + 1 })\n .toJSDate();\n }\n\n public setMonthDay(date: DateInput, day: number): Date {\n return this._dt(date).set({ day }).toJSDate();\n }\n\n public setHours(date: DateInput, hour: number): Date {\n return this._dt(date).set({ hour }).toJSDate();\n }\n\n public setMinutes(date: DateInput, minute: number): Date {\n return this._dt(date).set({ minute }).toJSDate();\n }\n\n public setSeconds(date: DateInput, second: number): Date {\n return this._dt(date).set({ second }).toJSDate();\n }\n\n public setMilliseconds(date: DateInput, millisecond: number): Date {\n return this._dt(date).set({ millisecond }).toJSDate();\n }\n\n public isBefore(date1: DateInput, date2?: DateInput): boolean {\n return this._dt(date1) < this._dt(date2);\n }\n\n public isAfter(date1: DateInput, date2?: DateInput): boolean {\n return this._dt(date1) > this._dt(date2);\n }\n\n public isValid(date: DateInput): boolean {\n return this._dt(date).isValid;\n }\n\n public isMatch(\n date: string,\n formatOrPatternKey: DateFormatPattern | (string & {}) = this.formatPatterns.dateTime\n ): boolean {\n return DateTime.fromFormat(date, this._resolve(formatOrPatternKey), { locale: this.locale, zone: this._zone })\n .isValid;\n }\n\n public isToday(date: DateInput): boolean {\n return this._isSame(date, undefined, \"day\");\n }\n\n public isSameMonth(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"month\");\n }\n\n public isSameDay(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"day\");\n }\n\n public isSameYear(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"year\");\n }\n\n public isSameHour(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"hour\");\n }\n\n public isSameMinute(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"minute\");\n }\n\n public isSameSecond(left: DateInput, right?: DateInput): boolean {\n return this._isSame(left, right, \"second\");\n }\n\n public isDateInRange(\n date: DateInput,\n isSame: (left: DateInput, right: DateInput) => boolean,\n start?: DateInput,\n end?: DateInput\n ) {\n if (start && end) {\n return isSame(date, start) || isSame(date, end) || (this.isAfter(date, start) && this.isBefore(date, end));\n }\n return (start && isSame(date, start)) || (end && isSame(date, end)) || false;\n }\n\n public isSameDate(left: DateInput, right?: DateInput) {\n return this.isSameDay(left, right);\n }\n\n public isSameDateTime(left: DateInput, right?: DateInput) {\n return this.isSameSecond(left, right);\n }\n\n public isEqual(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GAAiBC,GAA4B;EAC/D,OAAO,KAAK,QAAQD,GAAMC,GAAO,QAAQ;CAC3C;CAEO,aAAaD,GAAiBC,GAA4B;EAC/D,OAAO,KAAK,QAAQD,GAAMC,GAAO,QAAQ;CAC3C;CAEO,cACLE,GACAgB,GACAC,GACAC,GACA;EAIA,OAHID,KAASC,IACJF,EAAOhB,GAAMiB,CAAK,KAAKD,EAAOhB,GAAMkB,CAAG,KAAM,KAAK,QAAQlB,GAAMiB,CAAK,KAAK,KAAK,SAASjB,GAAMkB,CAAG,IAElGD,KAASD,EAAOhB,GAAMiB,CAAK,KAAOC,KAAOF,EAAOhB,GAAMkB,CAAG,KAAM;CACzE;CAEO,WAAWrB,GAAiBC,GAAmB;EACpD,OAAO,KAAK,UAAUD,GAAMC,CAAK;CACnC;CAEO,eAAeD,GAAiBC,GAAmB;EACxD,OAAO,KAAK,aAAaD,GAAMC,CAAK;CACtC;CAEO,QAAQD,GAAiBC,GAAmB;EACjD,OAAO,KAAK,IAAID,CAAI,CAAC,CAAC,SAAS,MAAM,KAAK,IAAIC,CAAK,CAAC,CAAC,SAAS;CAChE;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weekwise/adapter-luxon",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Luxon adapter for the weekwise calendar.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"date-adapter"
|
|
27
27
|
],
|
|
28
28
|
"license": "MIT",
|
|
29
|
-
"author": "
|
|
29
|
+
"author": "Vadim Ilinchik",
|
|
30
30
|
"homepage": "https://weekwise.dev/guides/date-adapters/",
|
|
31
31
|
"repository": {
|
|
32
32
|
"type": "git",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"url": "https://github.com/ivp-dev/weekwise/issues"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@weekwise/core": "^0.
|
|
40
|
+
"@weekwise/core": "^0.3.1"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"luxon": "^3.4.0"
|