klog.js
Version:
A JavaScript implementation of the Klog time tracking file format
85 lines (84 loc) • 2.52 kB
TypeScript
import { DurationNode, Sign } from "./types.js";
declare const customInspect: unique symbol;
/**
* Options for formatting the duration.
*/
export interface DurationOptions {
/** Whether to explicitly show a positive sign. */
explicitPositive?: boolean;
/** The sign to use for zero values. */
zeroSign?: Sign;
}
/**
* Represents a duration of time in hours and minutes.
*/
export declare class Duration {
#private;
/** Whether to explicitly show a positive sign. */
explicitPositive: boolean;
/** The sign to use for zero values. */
zeroSign: Sign;
/**
* Create a new duration.
* @param hours - The number of hours.
* @param minutes - The number of minutes.
* @param options - Formatting options for the duration.
*/
constructor(hours: number, minutes: number, { explicitPositive, zeroSign }?: DurationOptions);
/** @internal */
static fromAST(node: DurationNode): Duration;
/**
* Create a new duration from a total number of minutes.
* @param value - The total number of minutes.
* @param options - Formatting options for the duration.
*/
static fromMinutes: (value: number, options?: DurationOptions) => Duration;
/**
* The number of minutes in the duration.
*/
get minutes(): number;
/**
* The number of hours in the duration.
*/
get hours(): number;
/**
* The sign of the duration. Takes the `zeroSign` option into account.
*/
get sign(): Sign;
/**
* Add another duration to this duration.
* @param other - The other duration to add.
* @returns A new Duration instance representing the sum.
*/
add(other: this): Duration;
/**
* Subtract another duration from this duration.
* @param other - The other duration to subtract.
* @returns A new Duration instance representing the difference.
*/
subtract(other: this): Duration;
/**
* Check if this duration is equal to another duration.
* @param other - The other duration to compare against.
*/
equals(other: this): boolean;
/**
* Render the duration as a Klog string.
*/
toString(): string;
/**
* Convert the duration to a JSON object.
*/
toJSON(): {
hours: number;
minutes: number;
zeroSign: Sign;
explicitPositive: boolean;
};
/**
* Converts the duration to minutes.
*/
toMinutes(): number;
[customInspect](): string;
}
export {};