dayjs-plugin-time-interval
Version:
A Dayjs plugin to add support for time intervals
44 lines (40 loc) • 1.6 kB
TypeScript
import dayjs from 'dayjs';
import duration from 'dayjs/plugin/duration';
type Pretty<T> = T extends T ? {
[K in keyof T]: T[K];
} : never;
declare const plugin: dayjs.PluginFunc;
declare namespace plugin {
interface TimeInterval {
readonly start: dayjs.Dayjs;
readonly end: dayjs.Dayjs;
readonly duration: duration.Duration;
clone(): TimeInterval;
isValid(unit?: dayjs.OpUnitType): boolean;
isSame(other: TimeInterval, unit?: dayjs.OpUnitType): boolean;
overlaps(other: TimeInterval, unit?: dayjs.OpUnitType): boolean;
includes(d: dayjs.ConfigType, unit?: dayjs.OpUnitType): boolean;
withStart(start: dayjs.ConfigType | ((start: dayjs.Dayjs) => dayjs.ConfigType)): TimeInterval;
withEnd(end: dayjs.ConfigType | ((end: dayjs.Dayjs) => dayjs.ConfigType)): TimeInterval;
toJSON(): string;
toISOString(): string;
format(formatStr?: string): {
start: string;
end: string;
};
}
type FullConfigType = {
start: dayjs.ConfigType;
end: dayjs.ConfigType;
duration: duration.Duration | duration.DurationUnitsObjectType;
};
type ConfigType = {
[K in keyof FullConfigType]: Pretty<Omit<FullConfigType, K>>;
}[keyof FullConfigType];
}
declare module "dayjs" {
function timeInterval(config: string, format?: string): plugin.TimeInterval;
function timeInterval(config: plugin.ConfigType): plugin.TimeInterval;
function isTimeInterval(t: unknown): t is plugin.TimeInterval;
}
export { plugin as default };