UNPKG

klog.js

Version:

A JavaScript implementation of the Klog time tracking file format

77 lines (76 loc) 2.32 kB
import { Duration } from "./duration.js"; import { TimeNode } from "./types.js"; /** * How a time should be formatted when turned into a string. */ export declare enum TimeFormat { TwentyFourHour = "24h", TwelveHour = "12h" } /** * Which day a time should be assigned to. */ export declare enum DayShift { Yesterday = -1, Today = 0, Tomorrow = 1 } /** * A specific time of day. */ export declare class Time { /** The hour of the time, in 24-hour format. */ hour: number; /** The minute of the time. */ minute: number; /** If the time belongs to today, tomorrow, or yesterday. */ dayShift: DayShift; /** The format to use for the time when rendering as a string. */ format: TimeFormat; /** * Create a new time. * @throws {Error} The time values are invalid. */ constructor( /** The hour of the time, in 24-hour format. */ hour: number, /** The minute of the time. */ minute: number, /** If the time belongs to today, tomorrow, or yesterday. */ dayShift?: DayShift, /** The format to use for the time when rendering as a string. */ format?: TimeFormat); /** @internal */ static fromAST: (node: TimeNode) => Time; /** * Validates the time values. * @param hour - The hour to validate. * @param minute - The minute to validate. * @param dayShift - The day shift to validate. * @returns True if the time values are valid, false otherwise. */ static isValidValue(hour: number, minute: number, dayShift?: DayShift): boolean; /** * Check if this time is equal to another time. * @param other - The time to compare against. */ equals(other: this): boolean; /** * Check if this time is after or equal to another time. * @param other - The other time to compare against. */ afterOrEquals(other: this): boolean; /** * Render the time as a Klog string. * @param formatOverride - Optional override for the time format. */ toString(formatOverride?: TimeFormat): string; /** * Convert the time to a duration starting at midnight. */ toDurationSinceMidnight(): Duration; /** * Convert the time to the amount of minutes since midnight. */ toMinutesSinceMidnight(): number; }