-
Hello, i'm trying to do a sleep calculation be automatic (using the tp.file.creation_date as time im going to sleep and tp.date.now as the time i wake up), but i can't make it to work. I started using de plugin some days ago, so i know little about it. (this is for a dream diary) <%* thats what i did, if someone can help me i would be very thankfull |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You got the basic gist right! Since Obsidian uses moment, we can use that with templater. <%*
var gt_sleep = moment(app.workspace.getActiveFile().stat.ctime);
var w_up = moment();
// below from stackoverflow: https://stackoverflow.com/a/29746202
// calculate total duration
var duration = moment.duration(w_up.diff(gt_sleep));
// duration in hours
var hours = parseInt(duration.asHours());
// duration in minutes
var minutes = parseInt(duration.asMinutes()) % 60;
var output = 'You slept: ' + hours + ' hour and ' + minutes + ' minutes.'
console.log(output);
tR += `${output}`
-%> |
Beta Was this translation helpful? Give feedback.
You got the basic gist right! Since Obsidian uses moment, we can use that with templater.
Demo