UNPKG

nhb-toolbox

Version:

A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.

74 lines (73 loc) 4.37 kB
import type { $Chronos, ChronosInput, TimeUnit } from '../types'; declare module '../Chronos' { interface Chronos { /** * @instance Returns the number of full years between the input date and the current instance. * @param time Optional time to compare with the `Chronos` date/time. Defaults to current time. * @returns The difference in number, negative if past, positive if future. */ getRelativeYear(time?: ChronosInput): number; /** * @instance Returns the number of full months between the input date and the current instance. * @param time Optional time to compare with the `Chronos` date/time. Defaults to current time. * @returns The difference in number, negative if past, positive if future. */ getRelativeMonth(time?: ChronosInput): number; /** * @instance Determines how many full weeks apart the input date is from the `Chronos` instance. * @param time Optional time to compare with the `Chronos` date/time. Defaults to current time. * @returns The difference in number, negative if past, positive if future. */ getRelativeWeek(time?: ChronosInput): number; /** * @instance Returns the number of full days between the input date and the current instance. * @param time Optional time to compare with the `Chronos` date/time. Defaults to current time. * @returns The difference in number, negative if past, positive if future. */ getRelativeDay(time?: ChronosInput): number; /** * @instance Determines how many full hours apart the input date is from the `Chronos` instance. * @param time Optional time to compare with the `Chronos` date/time. Defaults to current time. * @returns The difference in number, negative if past, positive if future. */ getRelativeHour(time?: ChronosInput): number; /** * @instance Returns the number of full minutes between the input date and the current instance. * @param time Optional time to compare with the `Chronos` date/time. Defaults to current time. * @returns The difference in number, negative if past, positive if future. */ getRelativeMinute(time?: ChronosInput): number; /** * @instance Returns the number of full seconds between the input date and the current instance. * @param time Optional time to compare with the `Chronos` date/time. Defaults to current time. * @returns The difference in number, negative if past, positive if future. */ getRelativeSecond(time?: ChronosInput): number; /** * @instance Returns the number of milliseconds between the input date and the current instance. * @param time Optional time to compare with the `Chronos` date/time. Defaults to current time. * @returns The difference in number, negative if past, positive if future. */ getRelativeMilliSecond(time?: ChronosInput): number; /** * @instance Compares the stored date with the current instance, returning the relative difference in the specified unit. * * @remarks * - Internally uses {@link getRelativeYear}, {@link getRelativeMonth}, {@link getRelativeWeek}, {@link getRelativeDay}, {@link getRelativeHour}, {@link getRelativeMinute}, {@link getRelativeSecond} and {@link getRelativeMilliSecond} and rounds the result. * - To calculate accurate difference use {@link diff} method. * * @param unit The time unit to compare by. Defaults to `'minute'`. * @param time Optional time to compare with the `Chronos` date/time. Defaults to current time. * @returns The difference in number, negative if past, positive if future. */ compare(unit?: TimeUnit, time?: ChronosInput): number; /** @instance Checks if the current date is today. */ isToday(): boolean; /** @instance Checks if the current date is tomorrow. */ isTomorrow(): boolean; /** @instance Checks if the current date is yesterday. */ isYesterday(): boolean; } } /** * Plugin to inject `relative time` related methods */ export declare const relativeTimePlugin: ($Chronos: $Chronos) => void;