(date: Date, options?: { isAlreadyLocal?: boolean })
| 992 | } |
| 993 | |
| 994 | async navigateToDailyNote(date: Date, options?: { isAlreadyLocal?: boolean }) { |
| 995 | try { |
| 996 | // Check if Daily Notes plugin is enabled |
| 997 | if (!appHasDailyNotesPluginLoaded()) { |
| 998 | new Notice( |
| 999 | "Daily notes core plugin is not enabled. Please enable it in settings > core plugins." |
| 1000 | ); |
| 1001 | return; |
| 1002 | } |
| 1003 | |
| 1004 | // Convert date to moment for the API |
| 1005 | // Fix for issue #857: Convert UTC-anchored date to local calendar date |
| 1006 | // before passing to moment() to ensure correct day is used |
| 1007 | // Fix for issue #1223: Skip conversion if the date is already local (e.g., from getTodayLocal()) |
| 1008 | const localDate = options?.isAlreadyLocal ? date : convertUTCToLocalCalendarDate(date); |
| 1009 | const moment = (window as Window & { moment: (date: Date) => DailyNoteMoment }).moment( |
| 1010 | localDate |
| 1011 | ); |
| 1012 | |
| 1013 | // Get all daily notes to check if one exists for this date |
| 1014 | const allDailyNotes = getAllDailyNotes(); |
| 1015 | let dailyNote = getDailyNote(moment, allDailyNotes); |
| 1016 | let noteWasCreated = false; |
| 1017 | |
| 1018 | // If no daily note exists for this date, create one |
| 1019 | if (!dailyNote) { |
| 1020 | try { |
| 1021 | dailyNote = await createDailyNote(moment); |
| 1022 | noteWasCreated = true; |
| 1023 | } catch (error) { |
| 1024 | const errorMessage = error instanceof Error ? error.message : String(error); |
| 1025 | tasknotesLogger.error("Failed to create daily note:", { |
| 1026 | category: "persistence", |
| 1027 | operation: "create-daily-note", |
| 1028 | error: error, |
| 1029 | }); |
| 1030 | new Notice(`Failed to create daily note: ${errorMessage}`); |
| 1031 | return; |
| 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | // Open the daily note |
| 1036 | if (dailyNote) { |
| 1037 | await this.app.workspace.getLeaf(false).openFile(dailyNote); |
| 1038 | |
| 1039 | // If we created a new daily note, refresh the cache to ensure it shows up in views |
| 1040 | if (noteWasCreated) { |
| 1041 | // Note: Cache rebuilding happens automatically on data change notification |
| 1042 | |
| 1043 | // Notify views that data has changed to trigger a UI refresh |
| 1044 | this.notifyDataChanged(dailyNote.path, false, true); |
| 1045 | } |
| 1046 | } |
| 1047 | } catch (error) { |
| 1048 | const errorMessage = error instanceof Error ? error.message : String(error); |
| 1049 | tasknotesLogger.error("Failed to navigate to daily note:", { |
| 1050 | category: "persistence", |
| 1051 | operation: "navigate-daily-note", |
no test coverage detected