Looking for a better explanation of the formatDuration() function


#1

1) Give a description of the problem
The wiki gives the syntax for this function as follows:

string formatDuration(datetime value[, boolean friendly = false[, string granularity = 's'[, boolean showAdverbs = false]]])

But it doesn’t actually want a datetime input. Examples in the wiki have integers, and feeding it a datetime results in an incorrect response.

2) What is the expected behavior?
There is no explicit explanation for the function in the wiki, but my assumption (yeah I know) is that giving it a datetime will return the duration since the datetime.

3) What is happening/not happening?
Providing a datetime returns a ridiculous result. The wiki’s examples show it using an integer, although the syntax asks for datetime.

4) Post a Green Snapshot of the pistonimage

There are no relevant logs.

Thanks!


#2

Here is how I am using this function in a WebCore Piston State update that monitors my waterfall pump and lets me know how long it has been operating :smile:


#3

Yep, that works. Changed to $now - lastOpen. I’ll try to create an account and update the wiki. Thanks.