liamcain / obsidian-periodic-notes

Create/manage your daily, weekly, and monthly notes in Obsidian
MIT License
987 stars 67 forks source link

“Unable to create new file” due to week-alignment issue #238

Open khaeru opened 2 weeks ago

khaeru commented 2 weeks ago

With:

…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:

  1. .startOf("week") gives a date 1 day prior to .startOf("isoWeek").
  2. 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):

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.

LandonSchropp commented 1 week ago

I can confirm that changing unitOfTime to "isoWeek" resolves the issue.

jkrcma commented 1 week ago

Experienced the same issue with almost exactly the same note format. Changing to isoWeek also worked for me, thanks!