mirror of
https://github.com/jacobtread/obsidian-timekeep.git
synced 2026-07-22 10:10:27 +00:00
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { moment } from "obsidian";
|
|
import { TimekeepSettings } from "@/settings";
|
|
|
|
export function formatTimestamp(
|
|
timestamp: moment.Moment,
|
|
settings: TimekeepSettings
|
|
): string {
|
|
return moment(timestamp).format(settings.timestampFormat);
|
|
}
|
|
|
|
export function formatEditableTimestamp(
|
|
timestamp: moment.Moment | string,
|
|
settings: TimekeepSettings
|
|
): string {
|
|
return moment(timestamp).format(settings.editableTimestampFormat);
|
|
}
|
|
|
|
export function unformatEditableTimestamp(
|
|
formatted: string,
|
|
settings: TimekeepSettings
|
|
): moment.Moment {
|
|
return moment(formatted, settings.editableTimestampFormat, true);
|
|
}
|
|
|
|
export function formatDuration(totalTime: number): string {
|
|
let ret = "";
|
|
const duration = moment.duration(totalTime);
|
|
const hours = Math.floor(duration.asHours());
|
|
|
|
if (hours > 0) ret += hours + "h ";
|
|
if (duration.minutes() > 0) ret += duration.minutes() + "m ";
|
|
ret += duration.seconds() + "s";
|
|
|
|
return ret;
|
|
}
|
|
|
|
export function formatDurationHoursTrunc(totalTime: number): string {
|
|
const duration = moment.duration(totalTime);
|
|
|
|
const hours = duration.asHours();
|
|
|
|
return hours.toFixed(2) + "h ";
|
|
}
|