Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
khaeru opened this issue Oct 28, 2024 · 2 comments
Open

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

khaeru opened this issue Oct 28, 2024 · 2 comments

Comments

@khaeru
Copy link

khaeru commented Oct 28, 2024

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:

weekly: {
unitOfTime: "week",
relativeUnit: "this week",
createNote: createWeeklyNote,
getNote: getWeeklyNote,
getAllNotes: getAllWeeklyNotes,
},

export async function openPeriodicNote(
periodicity: IPeriodicity,
date: Moment,
inNewSplit: boolean
): Promise<void> {
const config = periodConfigs[periodicity];
const startOfPeriod = date.clone().startOf(config.unitOfTime);

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

  • 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.

@LandonSchropp
Copy link

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

@jkrcma
Copy link

jkrcma commented Nov 5, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants