zincplusplus / habit-tracker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Provide a relative date function for lastDisplayDate

davetron33 opened this issue · comments

Hi here!

First of all, I love this plugin and the simplicity of creating a tracker based on folder structure. Thanks for making this!

I'm currently rendering the habit tracker in a template for my daily journaling and was wondering how, or if it's possible to use a relative date function as the input for lastDisplayedDate?

Say I open a file today, 21 days from now the final cell would be the 26th.

But if I open a file tomorrow, 21 days from then should be the 28th. But because lastDisplayedDate is set to a static date in my templates, each daily file has the same end date. Here's what it looks like when I don't provide lastDisplayedDate and try using the default "Today". The first day on the tracker starts on the 15th of last month and ends on today, instead of starting on today and ending 21 days from now.

image

Is that possible, or that outside the scope of the plugin?

Thanks for the kind words @davetron33

This is what I have in my daily notes template:

{
	"path": "Habits/Good/",
	"lastDisplayedDate": "{{date:YYYY-MM-DD}}"
}

I'm fairly sure the date is just replaced by the Daily notes plugin that comes pre-installed with Obsidian. Unfortunately I can't add an option in the plugin to have something like lastDisplayedDate: "today" because javascript doesn't know what day that note belongs to.

I can't look at the created date of the file, because I create mine in advance, the day before. And I also can't look at the last edited date because again users might make changes after the day has passed.

Please give the above code a try, and if it doesn't work let me know and I'll look into another solution.

@zoreet I think I may have been using your habit tracker "backwards". After trying your suggestion, and comparing with a default tracker, it immediately clicked and makes sense to me why I'm seeing prior days leading up to current working day in the notes, this isn't a problem with the date after all.

I think this can be closed now (filed under "pebcac" 😂 ), unless you would like to keep it open for other feature development to the date field.

Thanks for the response and thanks again for the handy plugin!

Cool, I'll close this.

By the way, the lastDisplayedDate parameter is optional. If it's not provided Habit Tracker 21 will always default to today.