Difference between revisions of "$duration"

From Scriptwiki
Jump to: navigation, search
(changed the table a bit as it did look weird (imo))
m (changed to wiki-pipe-tables + tweaked)
 
Line 6: Line 6:
 
  $duration(interval, N)
 
  $duration(interval, N)
  
$duration(3660) returns "1hr 1min".
+
* ''N'' is an optional parameter which specifies how $duration formats the time:
  
N is an optional parameter which specifies how $duration formats the time:
+
{| style="width:100%;"
 +
|-
 +
| style="width:5%;" |'''''N'''''
 +
| style="width:90%;" |'''''Meaning'''''
 +
|-
 +
| 2
 +
| do not include seconds in the result
 +
|-
 +
| 3
 +
| return in the H:m:s format
 +
|}
  
<table width="100%">
+
== Example ==
<tr><td width="5%"><b>N</b></td><td width="90%"><b>Meaning</b></td></tr>
 
<tr><td>2</td><td>do not include seconds in the result</td></tr>
 
<tr><td>3</td><td>$duration uses the H:m:s format</td></tr>
 
</table>
 
  
== Examples ==
+
$duration(3665)  ;returns ''1hr 1min 5secs''
 +
$duration(3665,2)  ;returns ''1hr 1min''
 +
$duration(3665,3)  ;returns ''01:01:05''
  
 
=== Time since a specific date ===
 
=== Time since a specific date ===
Line 27: Line 35:
  
 
  [[var]] %when = 1wk 3days 19hrs 41mins 15secs
 
  [[var]] %when = 1wk 3days 19hrs 41mins 15secs
  var %ts = $duration(%when) ;;This will give us the amount of seconds ''(934875)'' that is in ''%when''
+
  var %ts = $duration(%when) ;This will give us the amount of seconds ''(934875)'' that is in ''%when''
  var %ts = [[$calc]]([[$ctime]] + %ts) ;;Add ''$ctime'' (the current time in seconds) to the varible.
+
  var %ts = [[$calc]]([[$ctime]] + %ts) ;Add ''$ctime'' (the current time in seconds) to the varible.
 
  echo -a The date and time in %when will be [[$asctime]](%ts)
 
  echo -a The date and time in %when will be [[$asctime]](%ts)
 
[[Category:Time and Date Identifiers]]
 
[[Category:Time and Date Identifiers]]

Latest revision as of 20:11, 26 November 2005

Converts an interval (unit: seconds) in to a human-readable format. It is also capable of converting the human readable format in to total number of seconds elapsed since 00:00:00 GMT, January 1, 1970.

Note: When converting from human readable to numerical $duration will treat 1wk, 1w, 1week and 1 week as the same value. It is also worth noting that months and years do not have a set valid so can not be converted.

$duration(interval, N)
  • N is an optional parameter which specifies how $duration formats the time:
N Meaning
2 do not include seconds in the result
3 return in the H:m:s format

Example

$duration(3665)  ;returns 1hr 1min 5secs
$duration(3665,2)  ;returns 1hr 1min
$duration(3665,3)  ;returns 01:01:05

Time since a specific date

echo -a $duration($calc($ctime - $ctime(10.02.1986 00:00)))

This command echos how much time has passed since the 10th February 1986.

Reverting human readable text into an integer we can use to calculate

var %when = 1wk 3days 19hrs 41mins 15secs
var %ts = $duration(%when)  ;This will give us the amount of seconds (934875) that is in %when
var %ts = $calc($ctime + %ts)  ;Add $ctime (the current time in seconds) to the varible.
echo -a The date and time in %when will be $asctime(%ts)