MCPcopy
hub / github.com/callumalpass/tasknotes / updateTimeblockTimes

Function updateTimeblockTimes

src/utils/helpers.ts:869–895  ·  view source on GitHub ↗

* Updates timeblock times within the same daily note

(
	app: App,
	dailyNote: TFile,
	timeblockId: string,
	newStartTime: string,
	newEndTime: string
)

Source from the content-addressed store, hash-verified

867 * Updates timeblock times within the same daily note
868 */
869async function updateTimeblockTimes(
870 app: App,
871 dailyNote: TFile,
872 timeblockId: string,
873 newStartTime: string,
874 newEndTime: string
875): Promise<void> {
876 const content = await app.vault.read(dailyNote);
877 const frontmatter =
878 (extractFrontmatter(content) as DailyNoteFrontmatterWithTimeblocks | null) || {};
879
880 if (!frontmatter.timeblocks || !Array.isArray(frontmatter.timeblocks)) {
881 throw new Error("No timeblocks found in frontmatter");
882 }
883
884 // Update the timeblock
885 const timeblockIndex = frontmatter.timeblocks.findIndex((tb) => tb.id === timeblockId);
886 if (timeblockIndex === -1) {
887 throw new Error(`Timeblock ${timeblockId} not found`);
888 }
889
890 frontmatter.timeblocks[timeblockIndex].startTime = newStartTime;
891 frontmatter.timeblocks[timeblockIndex].endTime = newEndTime;
892
893 // Save back to file
894 await updateDailyNoteFrontmatter(app, dailyNote, frontmatter, content);
895}
896
897/**
898 * Removes a timeblock from a daily note

Callers 1

Calls 3

extractFrontmatterFunction · 0.70
readMethod · 0.45

Tested by

no test coverage detected