MCPcopy Index your code
hub / github.com/callumalpass/tasknotes / updateTimeblockInDailyNote

Function updateTimeblockInDailyNote

src/utils/helpers.ts:795–849  ·  view source on GitHub ↗
(
	app: App,
	timeblockId: string,
	oldDate: string,
	newDate: string,
	newStartTime: string,
	newEndTime: string
)

Source from the content-addressed store, hash-verified

793 * Updates a timeblock in a daily note's frontmatter
794 */
795export async function updateTimeblockInDailyNote(
796 app: App,
797 timeblockId: string,
798 oldDate: string,
799 newDate: string,
800 newStartTime: string,
801 newEndTime: string
802): Promise<void> {
803 const { getDailyNote, getAllDailyNotes, appHasDailyNotesPluginLoaded } = await import(
804 "obsidian-daily-notes-interface"
805 );
806
807 if (!appHasDailyNotesPluginLoaded()) {
808 throw new Error("Daily Notes plugin is not enabled");
809 }
810
811 const allDailyNotes = getAllDailyNotes();
812
813 // Get the timeblock from the old date
814 const oldMoment = getWindowMoment(oldDate);
815 const oldDailyNote = getDailyNote(oldMoment, allDailyNotes);
816
817 if (!oldDailyNote) {
818 throw new Error(`Daily note for ${oldDate} not found`);
819 }
820
821 const oldContent = await app.vault.read(oldDailyNote);
822 const timeblocks = extractTimeblocksFromNote(oldContent, oldDailyNote.path);
823
824 // Find the timeblock to move
825 const timeblockIndex = timeblocks.findIndex((tb) => tb.id === timeblockId);
826 if (timeblockIndex === -1) {
827 throw new Error(`Timeblock ${timeblockId} not found`);
828 }
829
830 const timeblock = timeblocks[timeblockIndex];
831
832 // If moving to same date, just update times
833 if (oldDate === newDate) {
834 await updateTimeblockTimes(app, oldDailyNote, timeblockId, newStartTime, newEndTime);
835 return;
836 }
837
838 // Remove from old date
839 await removeTimeblockFromDailyNote(app, oldDailyNote, timeblockId);
840
841 // Add to new date with updated times
842 const updatedTimeblock: TimeBlock = {
843 ...timeblock,
844 startTime: newStartTime,
845 endTime: newEndTime,
846 };
847
848 await addTimeblockToDailyNote(app, newDate, updatedTimeblock);
849}
850
851/**
852 * Copies a timeblock into a daily note with a new ID and time range.

Callers 2

handleTimeblockDropFunction · 0.90
handleTimeblockResizeFunction · 0.90

Calls 7

getAllDailyNotesFunction · 0.85
updateTimeblockTimesFunction · 0.85
addTimeblockToDailyNoteFunction · 0.85
getWindowMomentFunction · 0.70
readMethod · 0.45

Tested by

no test coverage detected