import * as i0 from '@angular/core'; import { Type, EnvironmentProviders, InjectionToken } from '@angular/core'; /** * @license * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE */ /** * Named format keys recognised by every {@link WrDateAdapter}. Adapters map * each key to their preferred locale-aware implementation (the native adapter * uses `Intl.DateTimeFormat`; a `date-fns` adapter would use its own tokens). * * `format()` / `parse()` also accept raw format strings — see the adapter's * implementation for the supported tokens (`yyyy`, `MM`, `dd`, `HH`, …). */ type WrDateFormat = 'shortDate' | 'mediumDate' | 'longDate' | 'time' | 'shortDateTime' | 'mediumDateTime'; /** * Options for {@link provideWrDateAdapter}. */ interface WrDateAdapterOptions { /** * Adapter class. Default: {@link WrNativeDateAdapter}. * * Pass a custom subclass to swap implementations (`WrDateFnsAdapter`, * `WrLuxonAdapter`, …). */ readonly adapter?: Type>; /** * BCP 47 locale tag (`'en-US'`, `'ru-RU'`, …). Default: `navigator.language` * in the browser, `'en-US'` on the server. */ readonly locale?: string; } /** * @license * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE */ /** * Abstraction over a date object so the calendar, date picker and time picker * can work with `Date`, `date-fns`, `luxon`, or any other library a consumer * prefers — without changing component code. * * Default implementation: {@link WrNativeDateAdapter} (native `Date`, * `Intl.DateTimeFormat`). Register a different adapter via * `provideWrDateAdapter({ adapter: MyAdapter })`. * * Used as both the type and the DI token — `inject(WrDateAdapter)` works * directly thanks to Angular's class-as-token resolution. * * Every "mutating" method (`addX`, `setTime`) returns a **new** value; * adapters never mutate in place so consumers can pass dates around safely. */ declare abstract class WrDateAdapter { /** Current moment. */ abstract today(): TDate; /** Defensive clone — must return an independent value, never the same reference. */ abstract clone(date: TDate): TDate; /** Build a date from year / month (0-based) / day. */ abstract createDate(year: number, month: number, day: number): TDate; /** `false` for `NaN` / invalid input. */ abstract isValid(date: TDate): boolean; abstract getYear(date: TDate): number; /** `0` (January) – `11` (December). */ abstract getMonth(date: TDate): number; /** Day of the month, `1`-`31`. */ abstract getDate(date: TDate): number; /** `0` (Sunday) – `6` (Saturday). */ abstract getDayOfWeek(date: TDate): number; abstract getDaysInMonth(date: TDate): number; abstract getHours(date: TDate): number; abstract getMinutes(date: TDate): number; abstract getSeconds(date: TDate): number; abstract addYears(date: TDate, amount: number): TDate; abstract addMonths(date: TDate, amount: number): TDate; abstract addDays(date: TDate, amount: number): TDate; /** Returns a new date with the time portion replaced. */ abstract setTime(date: TDate, hours: number, minutes: number, seconds: number): TDate; abstract isSameDay(a: TDate, b: TDate): boolean; abstract isSameMonth(a: TDate, b: TDate): boolean; /** Negative if `a < b`, positive if `a > b`, zero if equal (compared at day precision). */ abstract compareDate(a: TDate, b: TDate): number; /** * Convenience used by the calendar's range UI. Inclusive on both ends. * Implementation can stay on the base class because it delegates to * `compareDate`. */ isWithinRange(date: TDate, start: TDate, end: TDate): boolean; /** * Format a date. Accepts either a named {@link WrDateFormat} key (which the * adapter resolves locale-aware) or a raw format string (`'dd.MM.yyyy'`). * * Supported tokens for raw strings: `yyyy`, `yy`, `MMMM`, `MMM`, `MM`, `M`, * `dd`, `d`, `HH`, `H`, `hh`, `h`, `mm`, `ss`, `a` (am / pm). */ abstract format(date: TDate, formatKeyOrString: WrDateFormat | (string & {})): string; /** * Parse a string into a date. Returns `null` when parsing fails. Accepts * the same `formatKeyOrString` set as {@link format}. */ abstract parse(value: string, formatKeyOrString: WrDateFormat | (string & {})): TDate | null; /** `0` Sunday, `1` Monday — locale-dependent. */ abstract getFirstDayOfWeek(): number; /** Names ordered from `getFirstDayOfWeek()` onwards. Length 7. */ abstract getDayOfWeekNames(style: 'narrow' | 'short' | 'long'): readonly string[]; /** Names from January (index `0`) to December (`11`). Length 12. */ abstract getMonthNames(style: 'narrow' | 'short' | 'long'): readonly string[]; } /** Whether `value` is one of the shared named format keys. */ declare function isNamedFormat(value: string): value is WrDateFormat; /** * Reference {@link WrDateAdapter} implementation backed by the native `Date` * object and `Intl.DateTimeFormat`. Zero external dependencies. Suitable for * most apps — swap to a `date-fns` / `luxon` adapter only when you need * timezone-aware math or richer parsing. */ declare class WrNativeDateAdapter extends WrDateAdapter { private readonly locale; today(): Date; clone(date: Date): Date; createDate(year: number, month: number, day: number): Date; isValid(date: Date): boolean; getYear(date: Date): number; getMonth(date: Date): number; getDate(date: Date): number; getDayOfWeek(date: Date): number; getDaysInMonth(date: Date): number; getHours(date: Date): number; getMinutes(date: Date): number; getSeconds(date: Date): number; addYears(date: Date, amount: number): Date; addMonths(date: Date, amount: number): Date; addDays(date: Date, amount: number): Date; setTime(date: Date, hours: number, minutes: number, seconds: number): Date; isSameDay(a: Date, b: Date): boolean; isSameMonth(a: Date, b: Date): boolean; compareDate(a: Date, b: Date): number; format(date: Date, formatKeyOrString: WrDateFormat | (string & {})): string; parse(value: string, formatKeyOrString: WrDateFormat | (string & {})): Date | null; getFirstDayOfWeek(): number; getDayOfWeekNames(style: 'narrow' | 'short' | 'long'): readonly string[]; getMonthNames(style: 'narrow' | 'short' | 'long'): readonly string[]; private formatWithTokens; private parseWithTokens; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * @license * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE */ /** * Register the date adapter and locale used by the calendar / date picker / * time picker. Call once at bootstrap. * * @example * ```ts * bootstrapApplication(AppComponent, { * providers: [ * provideWrDateAdapter(), // native, browser locale * // provideWrDateAdapter({ locale: 'ru-RU' }), * // provideWrDateAdapter({ adapter: MyDateFnsAdapter, locale: 'fr' }), * ], * }); * ``` */ declare function provideWrDateAdapter(options?: WrDateAdapterOptions): EnvironmentProviders; /** * @license * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE */ /** * BCP 47 locale tag used by {@link WrDateAdapter} implementations for * formatting, parsing, and locale-derived defaults (first day of week, * month / day names). Defaults to `navigator.language` in the browser and * `'en-US'` on the server. * * Override via {@link provideWrDateAdapter}'s `locale` option. */ declare const WR_DATE_LOCALE: InjectionToken; export { WR_DATE_LOCALE, WrDateAdapter, WrNativeDateAdapter, isNamedFormat, provideWrDateAdapter }; export type { WrDateAdapterOptions, WrDateFormat };