/** * @file * * Mock of Obsidian's `DateValue`, the Bases value wrapping a date. */ import type { DateValue as DateValueOriginal } from 'obsidian'; import type { RenderContext } from './RenderContext.mjs'; import type { Value } from './Value.mjs'; import { NotNullValue } from './NotNullValue.mjs'; /** * Mock of Obsidian's `DateValue`, a Bases `Value` wrapping a `Date`, optionally with its time of day. The * icon follows that: `lucide-clock` when the value has its time, `lucide-calendar` when it does not. */ export declare class DateValue extends NotNullValue { date: Date; time: boolean; /** * The value type's identifier, `'Date'` - Obsidian's own name for this class of value. */ static type: string; /** * Creates a value wrapping a date. * * @param date - The wrapped date. * @param time - Whether the time of day is part of the value, and so of {@link DateValue.toString}. Defaults to * `true`, as in Obsidian. */ constructor(date: Date, time?: boolean); /** * Mock-only factory: creates a date value, spyable via `vi.spyOn(DateValue, 'create__')`. * * @param date - The wrapped date. * @param showTime - Whether the time of day is part of the value. Defaults to `true`. * @returns The new date value. */ static create__(date: Date, showTime?: boolean): DateValue; /** * Mock-only: views a value typed as Obsidian's `DateValue` as this mock. The numbered subclass variant of * `fromOriginalType__`. * * @param value - The value typed as the original `DateValue`. * @returns The same object, typed as the mock. */ static fromOriginalType3__(value: DateValueOriginal): DateValue; /** * Parses a date value from a string, as Obsidian does. `YYYY-MM-DD` gives a value without its time, at local * midnight. `YYYY-MM-DD HH:mm` or `YYYY-MM-DDTHH:mm`, with optional seconds, fraction and zone, gives a value with * its time. Any other string is rejected. * * @param input - The string to parse. * @returns The parsed value, or `null` when the string has neither shape. */ static parseFromString(input: string): DateValue | null; /** * Mock-only: views this mock as Obsidian's `DateValue` type. The numbered subclass variant of * `asOriginalType__`. * * @returns The same object, typed as the original `DateValue`. */ asOriginalType3__(): DateValueOriginal; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(DateValue.prototype, 'constructor3__')`. * * @param _date - The date the value was created with. * @param _showTime - Whether the value was created showing the time. */ constructor3__(_date: unknown, _showTime?: boolean): void; /** * Drops the time portion of this value. * * @returns This value when it has no time. Otherwise, a new value without its time, at local midnight of the same * day. */ dateOnly(): DateValue; /** * Compares this date with another, as Obsidian does: by instant, not by how the two print. * * @param other - The date to compare with. * @returns Whether both show their time or both do not, AND both stand for the same instant. So two * values a second apart are unequal even without their time, where their printed forms agree. */ equals(other: this): boolean; /** * Checks whether the value counts as true in a Bases formula. * * @returns Always `true`: a date is truthy. */ isTruthy(): boolean; /** * Lists the property keys {@link DateValue.objectAccess} answers for. * * @returns The inherited keys followed by the eight date parts, whether or not the value shows its time. */ keys(): string[]; /** * Loosely compares this date with a value of any type, as Obsidian does. * * A `StringValue` is parsed through {@link DateValue.parseFromString} first, so `DateValue` loosely * equals the text it would be read back from. Unlike {@link DateValue.equals}, the two sides need not * agree about showing their time: when either hides it, both are compared at their {@link * DateValue.dateOnly}, so a timestamped value loosely equals the plain day it falls on. * * @param other - The value to compare with. * @returns Whether `other` is - or parses to - a date standing for the same instant, at whichever * precision the two share. */ looseEquals(other: Value): boolean; /** * Reads a named part of the date. * * @param key - The property key, matched without regard to case. * @returns The part as a `NumberValue` — `month` counted from `1`, `timestamp` in milliseconds since the * epoch, and every other part read in local time — and otherwise whatever the base answers. */ objectAccess(key: string): null | Value; /** * Formats the date part of the value. * * @returns The local date as `YYYY-MM-DD`. */ printDate(): string; /** * Formats the time part of the value. * * @returns The local time as `HH:mm:ss`. */ printTime(): string; /** * Describes the date relative to now. * * @returns Moment's `fromNow` text, such as `3 days ago`. */ relative(): string; /** * Renders the value into an element, as Obsidian does: a DISABLED date input carrying the value, styled as * the app's metadata fields are. * * Whether the time is shown decides everything about it at once - the input's `type` is `datetime-local` * with a time and `date` without, and its `mod-datetime` / `mod-date` class follows the same flag. The * value it carries is {@link DateValue.toString}'s, which is exactly the format each input type expects. * * @param el - The element to render into. * @param _context - The rendering context; unused. */ renderTo(el: HTMLElement, _context: RenderContext): void; /** * Formats the value as `YYYY-MM-DD`, followed by `THH:mm:ss` when it has its time. * * @returns The formatted date, in local time. */ toString(): string; }