Templater icon indicating copy to clipboard operation
Templater copied to clipboard

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

Open looak opened this issue 2 months ago • 2 comments

Plugin information:

  • OS: Windows 10
  • Templater version: 1.16.0
  • Obsidian version: v1.5.12

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.

looak avatar Apr 08 '24 15:04 looak

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.

Zachatoo avatar Apr 10 '24 04:04 Zachatoo

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

looak avatar Apr 11 '24 20:04 looak