liamcain / obsidian-calendar-plugin

Simple calendar widget for Obsidian.
MIT License
1.63k stars 142 forks source link

Mismatch of calendar week and corresponding row of days #219

Open dmnkf opened 2 years ago

dmnkf commented 2 years ago

Before Submitting: Double-check that you are running the latest version of the plugin. The bug might have already been fixed 😄

Describe the bug

The week row doesn't correspond with the week it should be aligned to. While week 52 of the year should be from 2021-12-27 until 2022-01-01 it is aligned with the week before that (2021-12-20 to 2021-12-26).

image

This might just be a visual bug, however, there is more to it. It seems that the creation by click doesn't translate the calendar week to determine the date range but takes the aligned week row.

This leads to following error:

image

The 2nd week of 2022 is supposed to be week afterward. https://weeknumber.com/2

Steps to reproduce

Requires Periodic Notes.

  1. Create a weekly template that makes use of the weekday formatting {{monday:YYYY-MM-DD}} - {{sunday:YYYY-MM-DD}}
  2. Link the weekly template to periodic notes
  3. Create the weekly template via the calendar by pressing the desired week
  4. Error

Expected behavior

In my opinion, the best approach would be to align the weeks properly to their corresponding week row so there isn't any confusion

Screenshots

image

image

Environment (please specify)

OS

[Windows/macOS]

Obsidian Version (e.g. v0.10.6)

v0.13.14

Theme (if applicable):

Obsidian Nord, but also the same with the main theme

133501 commented 2 years ago

The confusion is the incorrect determination of the FIRST week of the year. According to link in README.md concerning week numbering wiki page https://en.wikipedia.org/wiki/Week#Week_numbering where it says:

Determining Week 1
In practice week 1 (W01 in ISO notation) of any year can be determined as follows:

If January 1 falls on a Monday, Tuesday, Wednesday or Thursday, then the week of January 1 is Week 1.
If January 1 falls on a Friday, Saturday, or Sunday however, then January 1 is considered to be part of the last week of the previous year and Week 1 will begin on the first Monday after January 1.

So in 2022 Jan1 is Saturday and so the first week should be, Jan 3 to 9.

The calendar plugin first week is Dec 27 to Jan 2 tho.

Hope it helps with debugging works. Thanks!

xeeban commented 2 years ago

This bug messes up the week numbers on the Calendar for 2022 and seems to trickle down to Periodic Notes using the wrong week number as well.

According to the ISO-8601 standard, the first week of the year is the week that contains that year's first Thursday (='First 4-day week').

133501 commented 2 years ago

Hi @DM1NIK and @xeeban, I discovered, that changing locale settings is what is governing this 'bug'. For me, the cs is working as stated on the wiki and in ISO-8601. Since I'm in Czech Rep. and cs is our locale it is logical, but I've totally missed this setting for the first time. Hope it helps!

xeeban commented 2 years ago

Setting mine to en-gb seems to work, but it feels weird to have to set it to that as I am not in the UK

wakatara commented 2 years ago

I agree with above posters. The issue is that the first week of the year is incorrectly determined with respect to the ISO standard. If we fix that calc it should fix the problem. Thanks to @xeeban on the en-gb fix (sadly en-ca did not work... :-) ). I used that as a workaround so as not to have this drive me crazy. Lol. =]