srg-kostyrko / obsidian-journal

MIT License
125 stars 8 forks source link

Proper syntax for date manipulation? #59

Closed ChristinWhite closed 4 months ago

ChristinWhite commented 4 months ago

I'm not sure if I've hit a bug or I'm just doing it wrong but the readme says:

You can do date manipulations using Moment.js manipulation rules, e.g. {{start_date+5d:format}} to add 5 days.

Template

I have the following in my daily note template:

{{date}}
{{date+1d}}
{{date+1:YYYY-MM-DD}}
{{date-1d}}
{{date-1d:YYYY-MM-DD}}

{{date+1}}
{{date+1day}}
{{date+1, day}}
{{date+1, 'day'}}
{{date.add(1, 'd')}}
{{date-1}}

For the sake of thoroughness I tried to cover some rather unlikely variations there.

Result

2024-07-07
{{date+1d}}
{{date+1:YYYY-MM-DD}}
{{date-1d}}
{{date-1d:YYYY-MM-DD}}

{{date+1}}
{{date+1day}}
{{date+1, day}}
{{date+1, 'day'}}
{{date.add(1, 'd')}}
{{date-1}}

Work Around

This ugly hack:

next-day: "[[<% moment(tp.file.title.split(" ")[0]).add(1, "d").format('YYYY-MM-DD - dddd, MMMM DD') %>]]"
previous-day: "[[<% moment(tp.file.title.split(" ")[0]).subtract(1, "d").format('YYYY-MM-DD - dddd, MMMM DD') %>]]"

As an aside, if there happens to be a way to pass a parameter from Journals to Templater I'd love to know how.

Environment

macOS: 14.5 (23F79) Obsidian: Version 1.6.5 (Installer 1.6.5) Journals: 1.3.0 Templater: 2.3.3

Templates/Daily Notes Core Plugins: Disabled Periodic Notes: Not-installed Trigger Templater on new file creation: Disabled

srg-kostyrko commented 4 months ago

Sorry for confusion This feature was merged into main but it is not released yet Looks like Obsidian shows Readme from main not from release tag

As an aside, if there happens to be a way to pass a parameter from Journals to Templater I'd love to know how. Journal plugin processes its variables before templater so your workaround can be changed to

next-day: "[[<% moment("{{date}}").add(1, "d").format('YYYY-MM-DD - dddd, MMMM DD') %>]]"
previous-day: "[[<% moment("{{date}}").subtract(1, "d").format('YYYY-MM-DD - dddd, MMMM DD') %>]]"

Please note quotes around variable to make it proper JS string

srg-kostyrko commented 4 months ago

Date manipulation was released in 1.4.0

ChristinWhite commented 4 months ago

Thanks, I really appreciate the help and I apologize for missing the fact that this was on a specific tag.