obsidian-periodic-notes
obsidian-periodic-notes copied to clipboard
“Unable to create new file” due to week-alignment issue
With:
- Obsidian 1.7.4
- periodic-notes 0.0.17
- Configuration including the following:
{ "weekly": { "format": "GGGG/[W]WW", "template": "Templates/periodic-notes-weekly.md", "folder": "Calendar", "enabled": true } }
…I see the following in the console when I invoke the command "Open weekly note":
Failed to create file: 'Calendar/2024/W43.md' Error: File already exists.
at t.<anonymous> (app.js:1:732669)
at app.js:1:237228
at Object.next (app.js:1:237333)
at a (app.js:1:236051)
I should note at this point that I am not a JavaScript developer. But this apparently occurs because of this code: https://github.com/liamcain/obsidian-periodic-notes/blob/5b96e4f14130b0c024edb5ddb7871d01d61d9522/src/commands.ts#L41-L47 https://github.com/liamcain/obsidian-periodic-notes/blob/5b96e4f14130b0c024edb5ddb7871d01d61d9522/src/commands.ts#L71-L77 I don't see this file in my Obsidian directory. Instead at .obsidian/plugins/periodic-notes/main.js there is a file including:
async function openPeriodicNote(periodicity, date, inNewSplit) {
const config = periodConfigs[periodicity];
const startOfPeriod = date.clone().startOf(config.unitOfTime);
I add some debug code:
const startOfPeriod = date.clone().startOf(config.unitOfTime);
const debugStartOfPeriod = date.clone().startOf("isoWeek");
new obsidian__default['default'].Notice(`${date} ${startOfPeriod} ${debugStartOfPeriod}`);
Now when I invoke the command, I see a notice bubble with text like:
Mon Oct 28 2024 20:19:48 GMT+0100
Sun Oct 27 2024 00:00:00 GMT+0200
Mon Oct 28 2024 00:00:00 GMT+0100
In short:
.startOf("week")gives a date 1 day prior to.startOf("isoWeek").- This behaviour changed at some point; it is not the same as recently (perhaps Obsidian prior to 1.7.0? I do not recall my update history exactly). In my experience, the periodic-notes behaviour has always been to treat Monday as the start of a new week, which aligns with ISO 8601.
I can imagine at least two possible reasons for (2):
- The behaviour was due to a code change in periodic-notes, Obsidian, Electron, or something further upstream. I don't know how to determine where this may have changed, or when.
- There was no code change, but some code has a bug related to the end of daylight savings time (note the GMT+0100 and GMT+0200 mixed in the debug output).
I managed to hack a workaround by modifying the abovementioned .js file to include:
const periodConfigs = {
...
weekly: {
unitOfTime: "week",
unitOfTime2: "isoWeek", /* ADDED */
relativeUnit: "this week",
createNote: createWeeklyNote_1,
getNote: getWeeklyNote_1,
getAllNotes: getAllWeeklyNotes_1,
},
...
and
const startOfPeriod = date.clone().startOf(config.unitOfTime2); /* CHANGED */
With this, the command works as expected.
I can confirm that changing unitOfTime to "isoWeek" resolves the issue.
Experienced the same issue with almost exactly the same note format. Changing to isoWeek also worked for me, thanks!
Is there a fork that has this correction/fix?
Had the same issue and the same fix worked. It seems like #66, #128, #233, #240 and a bunch of others could be related/duplicates.
Is there a fork that has this correction/fix?
There appear to be many forks. But the owner of this repo seems to have abandoned it without handing off maintenance to anyone, so it's pure guesswork as to which one is best to use 😢.
In addition to the current issue, I just ran into #245 and so ended up creating yet another fork of my own to collect these hacks on main.js. As mentioned above:
I should note at this point that I am not a JavaScript developer.
…so, I wouldn't suggest you use it, and I wouldn't be able to provide support. But it does contain the changes from the issue description.
Many users in this thread are opting to change the plugin's main.js file to use your ISOweek date instead of using the locale week date. I tried this solution and it worked for me as well. Another solution I haven't seen anyone mention is changing your periodic note settings. I was able to solve the problem by changing the date format.
I changed the week format from YYYY-[W]W -> YYYY-[W]w. "W" is the syntax for ISO week and "w" is the syntax for locale week.
I changed the week format from YYYY-[W]W -> YYYY-[W]w. W is the syntax for ISO week and w is the syntax for locale week.
I have also fixed the Calendar plugin using a similar fix as @khaeru . in the main.js for the calendar plugin, change the "default_week_format" and "default_weekly_note_format" values to match your periodic note settings. You can find these value by for "gggg-[W]ww". In my case I have replaced these values with "YYYY-[W]w" and now it works as intended.
Here's a fix that worked for me in editing main.js -- not sure how to show a diff here, so commenting out the deletions
relativeUnit: "this year",
createNote: createYearlyNote_1,
getNote: getYearlyNote_1,
// getAllNotes: getAllYearlyNotes_1,
getAllNotes: getAllYearlyNotes_1
};
async function openPeriodicNote(periodicity, date, inNewSplit) {
const config = periodConfigs[periodicity];
// const startOfPeriod = date.clone().startOf(config.unitOfTime);
/* Add lines */
let unitForStartOf = config.unitOfTime;
if (periodicity === "weekly") {
unitForStartOf = "isoWeek";
}
const startOfPeriod = date.clone().startOf(unitForStartOf);
/* End add lines */
let allNotes;
try {
allNotes = config.getAllNotes();`