/** * @file * * Mock of Obsidian's `DurationValue`, the Bases value wrapping a duration. */ import type { DateValue as DateValueOriginal, DurationValue as DurationValueOriginal } from 'obsidian'; import type { Value } from './Value.cjs'; import { NotNullValue } from './NotNullValue.cjs'; /** * Mock of Obsidian's `DurationValue`, a Bases `Value` wrapping a duration, which can shift a `DateValue` or result * from subtracting one date from another. */ export declare class DurationValue extends NotNullValue { years: number; months: number; days: number; hours: number; minutes: number; seconds: number; milliseconds: number; /** * The value type's identifier, `'Duration'` - Obsidian's own name for this class of value. */ static type: string; /** * The lucide icon name standing for this value's type. */ icon: string; /** * Creates a duration from its components. * * @param years - The number of years. * @param months - The number of months. * @param days - The number of days. * @param hours - The number of hours. * @param minutes - The number of minutes. * @param seconds - The number of seconds. * @param milliseconds - The number of milliseconds. */ constructor(years: number, months: number, days: number, hours: number, minutes: number, seconds: number, milliseconds: number); /** * Mock-only factory: creates a duration, spyable via `vi.spyOn(DurationValue, 'create__')`. * * @param years - The number of years. * @param months - The number of months. * @param days - The number of days. * @param hours - The number of hours. * @param minutes - The number of minutes. * @param seconds - The number of seconds. * @param milliseconds - The number of milliseconds. * @returns The new duration. */ static create__(years: number, months: number, days: number, hours: number, minutes: number, seconds: number, milliseconds: number): DurationValue; /** * Creates a duration from a number of milliseconds. * * @param milliseconds - The length of the duration. * @returns A duration whose only non-zero component is its milliseconds. */ static fromMilliseconds(milliseconds: number): DurationValue; /** * Mock-only: views a value typed as Obsidian's `DurationValue` as this mock. The numbered subclass variant of * `fromOriginalType__`. * * @param value - The value typed as the original `DurationValue`. * @returns The same object, typed as the mock. */ static fromOriginalType3__(value: DurationValueOriginal): DurationValue; /** * Parses a duration from a string, as Obsidian does. * * It first searches the string for an ISO 8601 duration with a time part, such as `P1Y2M3DT4H5M6S` or `PT0S`. The * search is unanchored, and a duration without `T`, such as `P3D`, does not match. Weeks add seven days each. * Failing that, the whole string must be one signed integer and unit, with at most one space between them: * `3 days`, `-2h`, `1 week`. The units are `s`, `m` (minutes), `h`, `d`, `w`, `M` (months) and `y`, or the words * `second`, `minute`, `hour`, `day`, `week`, `month` and `year`, singular or plural. * * @param input - The string to parse. * @returns The parsed duration, or `null` when the string has neither shape. */ static parseFromString(input: string): DurationValue | null; /** * Shifts a date by this duration, one calendar component at a time: years, months, days, then hours, minutes, * seconds and milliseconds. * * @param value - The date to shift. * @param subtract - Whether to subtract the duration instead of adding it. * @returns A new date value. It has its time when `value` has, or when any of this duration's hours, minutes, * seconds or milliseconds is non-zero. */ addToDate(value: DateValueOriginal, subtract?: boolean): DateValueOriginal; /** * Mock-only: views this mock as Obsidian's `DurationValue` type. The numbered subclass variant of * `asOriginalType__`. * * @returns The same object, typed as the original `DurationValue`. */ asOriginalType3__(): DurationValueOriginal; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(DurationValue.prototype, 'constructor3__')`. * * @param _years - The years the duration was created with. * @param _months - The months the duration was created with. * @param _days - The days the duration was created with. * @param _hours - The hours the duration was created with. * @param _minutes - The minutes the duration was created with. * @param _seconds - The seconds the duration was created with. * @param _milliseconds - The milliseconds the duration was created with. */ constructor3__(_years: number, _months: number, _days: number, _hours: number, _minutes: number, _seconds: number, _milliseconds: number): void; /** * Compares this duration with another, as Obsidian does: field by field, rather than by how the two * print. * * It is deliberately NOT a comparison of length: `7 days` and `1 week` are stored as different fields — * a week parses to seven days, but a month never becomes days — so two durations of the same length in * different units are unequal here and loosely equal through {@link DurationValue.looseEquals}. * * @param other - The duration to compare with. * @returns Whether all seven components match. */ equals(other: this): boolean; /** * Converts this duration to milliseconds, as Obsidian does: by adding it to the current date and measuring the * difference. Months and years therefore have their calendar length from now, and the result depends on the * current date (and the local time zone's daylight-saving shifts). * * @returns The length of the duration in milliseconds, measured from now. */ getMilliseconds(): number; /** * Checks whether the value counts as true in a Bases formula. * * @returns Whether any component of the duration is non-zero. */ isTruthy(): boolean; /** * Lists the property keys {@link DurationValue.objectAccess} answers for. * * @returns The inherited keys followed by the eight units, in Obsidian's own order. */ keys(): string[]; /** * Loosely compares this duration with a value of any type, as Obsidian does: by LENGTH rather than by * components, so `1 week` loosely equals `7 days` where {@link DurationValue.equals} separates them. * * A `StringValue` is parsed through {@link DurationValue.parseFromString} first, so a duration loosely * equals the text it would be read back from. The length is {@link DurationValue.getMilliseconds}, * which Obsidian measures FROM NOW, so a comparison involving months or years depends on the current * date. * * @param other - The value to compare with. * @returns Whether `other` is - or parses to - a duration of the same length. */ looseEquals(other: Value): boolean; /** * Measures the duration in a named unit. * * @param key - The unit name, matched without regard to case. * @returns The duration as a `NumberValue` in that unit, and otherwise whatever the base answers. It is * measured as Obsidian measures it — by shifting the current date by this duration and taking moment's * fractional difference — so a duration in months or years has its calendar length FROM NOW, and the * answer depends on the current date and the local time zone's daylight-saving shifts. */ objectAccess(key: string): null | Value; /** * Formats the duration as text. * * @returns Moment's humanized text for the duration's components, such as `3 days` or `a few seconds`. */ toString(): string; }