What time is now + X minutes?

I am almost sure I saw some comprehensive post about “time calculations” within the past half year but I can’t find it or maybe I’m mistaken. Specifically, I’m interested in what time it is in “now + X minutes”.

Does anyone know of a writeup? This should probably even be a doc article.

Eric has a lot of time and date resources here It's About Time! — TiddlyTools: "Small Tools for Big Ideas!" (tm)

In some ways it is a simple maths question with a need to deal with the overflow, for example if you add minutes beyond the hour or hours beyond the day. You always need to handle one more than your scope. For example if it is only for day planning, you need only deal with up to the new day detection. mins > hours > day

Yeah, I did check out Erics fantastic page but it doesn’t have or explain this.

But, @EricShulman , do you have any advice? I’m guessing you have faced this in spades?

Generally, I just figured there could be filter operators to add or subtract time. Maybe a set of suffixes to the add and subtract ops so one could do e.g
"20211002153802059 +[add:minutes[150]]" or some such.

It sounds like add-time from DateMacros might work?

I’m glad you brought up this topic, because I didn’t think to check while working on a recent project and I ended hacking together a nasty filter that used format:relativedate and compare:string:eq to find tiddlers modified N days ago :grimacing:

Whoa! Good ol’ Jedster is ahead of the times again with some fossilized script. Thank you @hoelzro and @inmysocks

Hello,

As a side note, in cas anyone is interrested, I am sharing some macros to help with date operations :
https://dates-macros.tiddlyhost.com/

The macros convert between date format (like 2022-03-07 or its TiddlyWiki equivalent format 20220307…) and time stamp (linux time).
The idea is that date / time operations are easier to achieve with timestamps.

Some demonstration are also provided.

Best regards,

Eskha

For a really compact javascript macro that converts dates, see:

https://tiddlytools.com/timer.html#TiddlyTools%2FTime%2FConvertDate

-e

Thanks everyone.

I find no direct solution to my problem but based on one of Jeds scripts and google I got something working. The complete tiddler is here but the main part is here below:

I don’t know js so maybe someone can tell me if anything is bad about it. The idea is to call the function with a number and get the current time (hours:minutes) with that many added minutes.

One detail that I don’t know how to achieve is a padding 0 for single-digit hours, but I can live without it.

(function(){

"use strict";

exports.name = "add-minutes";

exports.params = [
	{name: "minutes"}
];

exports.run = function(minutes) {
	var currentDate = new Date();

	var output_hours = new Date(currentDate.getTime() + minutes*60000).getHours();
	var output_minutes = new Date(currentDate.getTime() + minutes*60000).getMinutes();
	
	var result = output_hours + ":" +output_minutes;

	return result;
};
1 Like

For the record:

I couldn’t live without it and it was solved like so:

var result = ('0'+output_hours).slice(-2) + ":" + ('0'+output_minutes).slice(-2);

2 Likes