/** * Limits a value to be between min and max (inclusive). * * @example * * ```ts * const min = FDate.fromIso("2004-08-01"); * const max = FDate.fromIso("2007-05-31"); * * clamp(FDate.fromIso("2005-12-31"), min, max); // -> FDate { 2005-12-31 } in range * clamp(FDate.fromIso("2004-07-31"), min, max); // -> FDate { 2004-08-01 } min * clamp(FDate.fromIso("2007-06-01"), min, max); // -> FDate { 2007-05-31 } max * ``` * * @public * @since v6.12.0 * @param value - The value to limit. * @param min - The lower bound (inclusive). * @param max - The upper bound (inclusive). * @returns A value between min and max (inclusive). */ export declare function clamp>(value: T, min: T, max: T): T; /** * Represents a clampable value. * * @public */ export declare interface Clampable { isBefore(rhs: T): boolean; isAfter(rhs: T): boolean; } /** * What format to use when formatting dates. * * @public */ export declare enum DateFormat { /** * Format with weekday, day, month, year as a human-readable string. * * "onsdag 4 maj 2022" */ FULL = "full", /** * Format with day, month, year as a human-readable string. * * "4 maj 2022" */ LONG = "long", /** * Format according to ISO 8601 format. * * "2022-05-04" */ ISO8601 = "iso-8601", /** * Format YYYYMMDD * * "20220504" */ YYYYMMDD = "YYYYMMDD" } /** * Represents a date (with year, month and day). * * @public */ export declare class FDate implements IterableDate, Clampable { private value; private constructor(); /* Excluded from this release type: invalid */ /** * Create {@link FDate} from current date. * * ``` * FDate.now() * ``` * * @public */ static now(): FDate; /** * Create {@link FDate} from ISO8601 string. * * ``` * FDate.fromIso("2022-04-20") * ``` * * @public */ static fromIso(value: string): FDate; /** * Create {@link FDate} from `Date`. * * ``` * FDate.fromDate(new Date()) * ``` * * @public */ static fromDate(value: Date): FDate; /** * Create {@link FDate} from year, month, day. * * ``` * FDate.fromYearMonthDay(2023, 1, 1) // => 2023-01-01 * FDate.fromYearMonthDay("2023", "01", "01") // => 2023-01-01 * ``` * * @public */ static fromYearMonthDay(year: FYear | number | string, month: number | string, day: number | string): FDate; /** * Get the year. * * ``` * FDate.now().year()// => 2022 * ``` * * @public */ get year(): number; /** * Get the month. * * Months are one-indexed, so January is month 1. * * ``` * FDate.now().month()// => 1-12 * ``` * * @public */ get month(): number; /** * Get the week according to the Swedish locale. * * @public */ get week(): number; /** * Get the day of the month. * * ``` * FDate.now().day// => 1-31 * ``` * * @public */ get day(): number; /** * Get the name of the month. * * ``` * FDate.now().monthName// => January * ``` * * @public */ get monthName(): string; /** * Get the short name of the month. * * ``` * FDate.now().monthNameShort// => Jan * ``` * * @public */ get monthNameShort(): string; /** * Get the name of the day. * * ``` * FDate.now().dayName// => Monday * ``` * * @public */ get dayName(): string; /** * Get the short name of the day. * * ``` * FDate.now().dayNameShort// => Mon * ``` * * @public */ get dayNameShort(): string; /** * Get number of the day in a week. * Returns `Weekday` enum. * If date is invalid, `0` is returned. * * ``` * FDate.now().weekDay// => Weekday.MONDAY / 1 * ``` * * @public */ get weekDay(): Weekday | 0; /** * This returns a `boolean` indicating whether the FDate object contains a valid date or not. * * ``` * FDate().isValid()// => boolean * ``` * * @public */ isValid(): boolean; /** * Returns a cloned {@link FDate} object and set it to the start of month. * * @public */ startOfMonth(): FDate; /** * Returns a cloned {@link FDate} object and set it to the end of month. * * @public */ endOfMonth(): FDate; /** * Returns a new {@link FDate} object with a specified amount of days added. * Specify a negative amount in order to subtract days. * * ``` * FDate().addDays(7)// => FDate * ``` * * @public */ addDays(value: number): FDate; /** * Returns a cloned {@link FDate} object with a specified amount of months added. * Specify a negative amount in order to subtract months. * * ``` * FDate().addMonths(7)// => FDate * ``` * * @public */ addMonths(value: number): FDate; /** * Returns a new {@link FDate} object with a specified amount of years added. * Specify a negative amount in order to subtract years. * * ``` * FDate().addYears(7)// => FDate * ``` * * @public */ addYears(value: number): FDate; /** * Returns a new {@link FDate} object with the date before This one. * * @public * @since v6.12.0 */ previous(): FDate; next(): FDate; /** * Compares two {@link FDate} objects and returns `true` if they represent the * same date. * * Invalid dates always returns `false`. * * @public * @param rhs - The date to compare with. * @returns `true` if the dates represent the same date. */ equals(rhs: FDate | string): boolean; /** * Returns true if this date is before given date. * * If the dates are the same this function returns false. */ isBefore(rhs: FDate | string): boolean; /** * Returns true if this date is after given date. * * If the dates are the same this function returns false. */ isAfter(rhs: FDate | string): boolean; /** * Compares two {@link FDate} objects. Returns and integer indicating whenever * `a` comes before or after or is equal to `b`. * * - `-1` if `a` beomes before `b`. * - `0` if `a` and `b` are the same date. * - `1` if `a` beomes after `b`. * * If either or both date is invalid the result is undefined behaviour and * should not be relied on. Use {@link FDate.isValid} to ensure validity * first, e.g. `myArray.filter(it => it.isValid())` before sorting. * * @public * @param a - First date object to compare. * @param b - Second date object to compare. * @returns `-1`, `0` or `1` */ static compare(a: FDate | string, b: FDate | string): number; /** * Returns a string representation of the date. * * ``` * FDate().toString() // "2022-05-04" * FDate().toString(DateFormat.FULL) // "onsdag 4 maj 2022" * FDate().toString(DateFormat.LONG) // "4 maj 2022" * FDate().toString(DateFormat.ISO8601) // "2022-04-20" * ``` * * @public * @param format - Format to use. */ toString(format?: DateFormat): string; /** * To serialize as an ISO8601 string. * * ``` * FDate().toJSON() // "2019-01-25" * ``` * * @public */ toJSON(): string; } /** * Represents a year. * * @public * @since v6.12.0 */ export declare class FYear implements IterableDate, Clampable { private _value; private constructor(); /** * Create {@link FYear} from current date. * * @example * * ```ts * FYear.now(); * ``` * * @public */ static now(): FYear; /** * Create {@link FYear} from a year (stored as number or string with four * digits). * * @example * * ```ts * FYear.fromYear(1999); * FYear.fromYear("1999"); * ``` * * @public * @param value - The year to set the `FYear` object to. */ static fromYear(value: number | string): FYear; /** * Create {@link FYear} from an `FDate` or `Date` object. * * @example * * ```ts * FYear.fromDate(FDate.now()); * FYear.fromDate(new Date()); * ``` * * @public * @param value - The date to get year from. */ static fromDate(value: FDate | Date): FYear; /** * Get the year as number (four digits) * * ``` * FYear.now().value; // => 1999 * ``` * * @public */ get value(): number; /** * This returns a `boolean` indicating whether the FYear object contains a * valid year or not. * * ``` * FYear().isValid(); // => boolean * ``` * * @public */ isValid(): boolean; /** * Returns a new {@link FYear} object with a specified amount of years * added. Specify a negative amount in order to subtract years. * * ``` * FYear().addYears(7); // => FYear * ``` * * @public * @param amount - The amount of years to add to this one. */ addYears(amount: number): FYear; /** * Returns a new {@link FYear} object with the year before this one. * * ``` * FYear(2025).previous(); // => FYear { 2024 } * ``` * * @public */ previous(): FYear; /** * Returns a new {@link FYear} object with the year after this one. * * ``` * FYear(2025).next(); // => FYear { 2026 } * ``` * * @public */ next(): FYear; /** * Compares two {@link FYear} objects and returns `true` if they represent * the same year. * * Invalid dates always returns `false`. * * @public * @param rhs - The year to compare with. * @returns `true` if the years are the same. */ equals(rhs: FYear | number | string): boolean; /** * Returns true if this year is before given year. * * If the years are the same this function returns false. * * @public * @param rhs - The year to compare with. * @returns `true` if this year is before given year. */ isBefore(rhs: FYear | number | string): boolean; /** * Returns true if this year is after given year. * * If the years are the same this function returns false. * * @public * @param rhs - The year to compare with. * @returns `true` if this year is after given year. */ isAfter(rhs: FYear | number | string): boolean; /** * Compares two {@link FYear} objects. Returns and integer indicating * whenever `a` comes before or after or is equal to `b`. * * - `-1` if `a` beomes before `b`. * - `0` if `a` and `b` are the same year. * - `1` if `a` beomes after `b`. * * If either or both years is invalid the result is undefined behaviour and * should not be relied on. Use {@link FYear.isValid} to ensure validity * first, e.g. `myArray.filter(it => it.isValid())` before sorting. * * @example * * ```ts * yearArray.sort(FYear.compare); * ``` * * @public * @param a - First year object to compare. * @param b - Second year object to compare. * @returns `-1`, `0` or `1` */ static compare(a: FYear | number | string, b: FYear | number | string): number; /** * Returns a string representation of the year. * * @public */ toString(): string; /** * Serializes to a JSON value. * * @public */ toJSON(): number | null; /* Excluded from this release type: toFYear */ /* Excluded from this release type: toValue */ } /** * Get current locale. * * Swedish locale is default. * * @public */ export declare function getLocale(): Locale; /** * Returns naming details for each weekday. * * If no locale is specified, the current locale will be used. * * @public */ export declare function getWeekdayNamings(locale?: Locale): WeekdayNaming[]; /** * Returns days in period grouped by week. * * @public */ export declare function groupByWeek(begin: FDate, end: FDate): Array<{ week: number; days: FDate[]; }>; /** * Check if given value is a {@link Locale}. * * @public */ export declare function isLocale(value?: Locale | string): value is Locale; /** * Represents a date unit than can be iterated over. * * @public */ export declare interface IterableDate { /** returns true if two date units represents the same date */ equals(rhs: T): boolean; /** returns true if this date is before the other (false if they are the same */ isBefore(rhs: T): boolean; /** returns the next date (e.g. next day, week, month, etc) */ next(): T; } /** * What locale to use when formatting days. * * @public */ export declare enum Locale { SWEDISH = "sv", ENGLISH = "en" } /** * Create and iterator for looping over a date period, e.g. every date between * `begin` and `end`. Both `begin` and `end` will be included. * * Since this is an iterator remember evaluation is lazy and to use * `Array.from(..)` if you need a proper array. * * @example * * Loop over every date between begin and end: * * ```ts * for (const date of range(begin, end)) { * // do something with date * } * ``` * * Save an array with all dates between begin and end: * * ```ts * const dates = Array.from(range(begin, end)) * ``` * * @public * @param begin - First date (inclusive) * @param end - Last date (inclusive) */ export declare function range>(begin: T, end: T): Generator; /** * Reset current locale to its default value. * * @public */ export declare function resetLocale(): void; /** * Set current locale. * * @public */ export declare function setLocale(locale: Locale): void; /** * Days in a week. * MONDAY(1) to SUNDAY(7) * * @public */ export declare enum Weekday { MONDAY = 1, TUESDAY = 2, WEDNESDAY = 3, THURSDAY = 4, FRIDAY = 5, SATURDAY = 6, SUNDAY = 7 } /** * Weekday naming. * * @public */ export declare interface WeekdayNaming { weekday: Weekday; name: string; shortName: string; } export { }