SilentVoid13 / Templater

A template plugin for obsidian
https://silentvoid13.github.io/Templater
GNU Affero General Public License v3.0
2.95k stars 169 forks source link

tp.date.weekday offset by one day. Perhaps due to leap year? #1352

Open looak opened 2 months ago

looak commented 2 months ago

Plugin information:

Describe the bug tp.date.weekday is offset by one, gives date of last weeks sunday.

Expected behavior tp.date.weekday, given 0 should give the date of current weeks monday.

Screenshots this is my template:

# Week Ahead

## Monday 
[[<% tp.date.weekday("Do of MMMM YYYY", 0) %>]]

result: created: 2024-04-08 07:50

Week Ahead

Monday

[[7th of April 2024]]

Additional context I believe something is going wrong considering we're in a leap year.

Zachatoo commented 2 months ago

I believe the behavior needs to be documented better. Templater is using the weekday function from moment. Here's a line from the moment documentation.

If the locale assigns Monday as the first day of the week, moment().weekday(0) will be Monday. If Sunday is the first day of the week, moment().weekday(0) will be Sunday.

The locale in Obsidian depends on the locale on your device. The Templater docs should make this behavior more clear.

looak commented 2 months ago

Thanks for getting back to me, you're correct, my locale was set to Sunday as first day of the week.