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

Week opens in wrong year #333

Open
steynh opened this issue Oct 7, 2023 · 5 comments
Open

Week opens in wrong year #333

steynh opened this issue Oct 7, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@steynh
Copy link

steynh commented Oct 7, 2023

Describe the bug

Clicking on a week opens that week, but then a year earlier.

Steps to reproduce

  1. Configure week format as "gggg-[W]WW" in Periodic Notes settings
  2. Navigate to September 2023 in Calendar view
  3. Click on '40' (in the week column)
  4. A note with title "2022-W40" is opened.

Expected behavior

Expected to open the "2023-W40" note.

Environment (please specify)

This bug was introduced recently.

SYSTEM INFO:
	Obsidian version: v1.4.12
	Installer version: v1.3.5
	Operating system: Darwin Kernel Version 22.4.0: Mon Mar  6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000 22.4.0
	Login status: logged in
	Catalyst license: none
	Insider build toggle: off
	Live preview: on
	Legacy editor: off
	Base theme: adapt to system
	Community theme: Things v2.1.11
	Snippets enabled: 3
	Restricted mode: off
	Plugins installed: 23
	Plugins enabled: 18
		1: Dataview v0.5.56
		2: Templater v1.16.0
		3: Tag Wrangler v0.5.6
		4: Style Settings v1.0.6
		5: Book Search v0.5.10
		6: QuickAdd v0.5.5
		7: Auto Note Mover v1.2.0
		8: Advanced Tables v0.18.1
		9: Jump to link v0.4.4
		10: Advanced URI v1.33.0
		11: CSV Table v1.2.0
		12: Calendar v1.5.10
		13: Folgezettel v1.0.0
		14: Relative Line Numbers v2.0.1
		15: Vimrc Support v0.9.0
		16: Obsidian Git v2.20.6
		17: Supercharged Links v0.9.0
		18: Periodic Notes v0.0.17

OS

macOS

Obsidian Version (e.g. v0.10.6)

v1.4.12

@steynh steynh added the bug Something isn't working label Oct 7, 2023
@schobernoise
Copy link

schobernoise commented Oct 29, 2023

I just encountered the same bug. It has been some time since I used weekly notes with calendar, but a year ago they worked as designed.

Calender now shows and opens Weekly Notes form a year ago. It works fine when creating new weekly notes. I tried switching locale, deactivating periodic notes and daily notes.

Weekly Note format: yyyy/[KW]ww/[KW]ww
Weekly Note Folder: Journal

Example: Journal/2023/KW43/KW43.md

@Inmovilizame
Copy link

Same for me... it finds past weeks even in a subfolder

@rajrajhans
Copy link

rajrajhans commented Dec 8, 2023

The issue seems to be in getDateFromFile function, it is using the basename of the each note file, which gives wrong year date if your weekly note file's basename does not include the year.

Here's a workaround for this: in .obsidian/plugins/calendar/main.js search for function getDateFromFile, patch the getDateFromFile function by adding the following code after getSettings object is declared:

  if (granularity === 'week') {
    const filePathParts = file.path.split('/');
    const year = filePathParts[1];
    const basename = filePathParts[filePathParts.length - 1];
    const dateString = `${year}/${basename}`;
    const formatString = `YYYY/${getSettings[granularity]()
      .format.split('/')
      .pop()}[.md]`;

    return window.moment(dateString, formatString, true);
  }

restarting obsidian after this change should fix the problem. (you might have to tweak the code a bit depending on your format for weekly note. mine is gggg/MM/[Week]-w)

@Inmovilizame
Copy link

@rajrajhans Thanks for the tip... I've adapted it to my particular folder setup. Although I've found that the problem seems to be associated with momentjs not parsing correctly the default format string gggg-[W]WW in getDateFromFile function:

    const format = getSettings[granularity]().format.split("/").pop();
    const noteDate = window.moment(file.basename, format, true);

Changing it in Periodic Notes settings to GGGG-[W]WW sets the calendar plugin to work as expected. It should work regarding the case of the format, maybe an outdated momentjs library embedded in Obsidian?

@turesheim
Copy link

Changing it in Periodic Notes settings to GGGG-[W]WW sets the calendar plugin to work as expected. It should work regarding the case of the format, maybe an outdated momentjs library embedded in Obsidian?

Thanks @Inmovilizame. This did the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants