klog.js
Version:
A JavaScript implementation of the Klog time tracking file format
76 lines (75 loc) • 2.53 kB
TypeScript
import { Duration } from "./duration.js";
import { Entry } from "./entry.js";
import { Time } from "./time.js";
import { RecordNode } from "./types.js";
import { Summary } from "./summary.js";
export declare enum RecordDateFormat {
Dashes = 0,
Slashes = 1
}
/**
* A block of time entries for any given day.
*/
export declare class Record {
/** The date of the record. */
date: Date;
/** Entries belonging to the record. */
entries: Entry[];
/** Optional summary or tags associated with the entire record. */
summary: Summary | null;
/** The expected duration all the entries in the record should sum up to. */
shouldTotal: Duration | null;
/** What dividers should be used for the date when using `toString` */
dateFormat: RecordDateFormat;
/** Create a new record. */
constructor(
/** The date of the record. */
date: Date,
/** Entries belonging to the record. */
entries?: Entry[],
/** Optional summary or tags associated with the entire record. */
summary?: Summary | null,
/** The expected duration all the entries in the record should sum up to. */
shouldTotal?: Duration | null,
/** What dividers should be used for the date when using `toString` */
dateFormat?: RecordDateFormat);
/** @internal */
static fromAST: (node: RecordNode) => Record;
/**
* The currently open entry, if any.
*/
get openEntry(): Entry | null;
/**
* The date string formatted according to the record's date format.
*/
get dateString(): string;
/**
* Calculate the difference between the record's actual total duration and the expected total duration.
*/
shouldTotalDiff(): Duration;
/**
* Start a new time entry.
* @param startTime - The time when the new entry starts.
* @param summary - The new entry's summary.
* @throws {Error} There is already an open entry in the record.
*/
start(startTime: Time, summary?: Summary | null): void;
/**
* End the currently open time entry, if any.
* @param endTime - The time the open range will end.
* @throws {Error} There are no open entries in the record.
*/
end(endTime: Time): void;
/**
* Converts the total duration of all entries to minutes.
*/
toMinutes(): number;
/**
* Converts the total duration of all entries to a duration.
*/
toDuration(): Duration;
/**
* Render the record as a Klog string.
*/
toString(): string;
}