Site Tools


tdiff2

# $EPIC: tdiff2.txt,v 1.2 2007/03/01 03:26:44 jnelson Exp $

Synopsis:

$tdiff2(<seconds>)

Technical:

  • If the <seconds> argument is omitted, the empty string is returned
  • The argument is taken to be the number of seconds (floating point is permitted) between two timed events. The integer part of the number must be within the range 2147483647 to -2147483648.
  • $tdiff2() returns the number of elapsed seconds in the following format:
    <integer> is taken as everything before a '.' in <seconds>.
    <after> is taken as everything after a '.' in <seconds>.
    <tsec> is <integer> % 60;
    <tmin> is (<integer> / 60) % 60;
    <thour> is (<integer> / 3600) % 24;
    <tday> is (<integer> / 86400);
If <tday> is 0, then nothing
Otherwise, then "<tday>d "
  plus
If <thour> is 0, then nothing
Otherwise, then "<thour>h "
  plus
If <tmin> is 0, then nothing
Otherwise, then "<tmin>m "
  plus
If <tsec> is not zero or all of <tday>, <thour>, <tmin> are zero,
    or <after> exists, then 
  If <after> exists, <sec> is "<tsec>.<after>"
    then "<sec> seconds"
  If <tsec> is 1, then "<sec>s"
  Otherwise, then "<sec>s"

Practical:

These functions are useful for showing how much time has elapsed since a particular event. For instance, they can convert your idle time from the number of seconds to a more readable form.

Returns:

A human readable string representing some elapsed time.

Examples:

$tdiff(248576)      returns "2 days 21 hours 2 minutes 56 seconds"
$tdiff(-248576)     returns "-2 days -21 hours -2 minutes -56 seconds"
$tdiff2(248576)     returns "2d 21h 2m 56s"
$tdiff2(-248576)    returns "-2d -21h -2m -56s"
$tdiff2(3602)       returns "1h 2s"  Notice the absence of minutes.

History:

This function first appeared in ircII+CS

tdiff2.txt · Last modified: 2007/03/01 03:26 by 127.0.0.1