From WikiChip
Difference between revisions of "mirc/identifiers/$duration"
< mirc‎ | identifiers

m
m
Line 1: Line 1:
 
{{mirc title|$duration Identifier}}The '''$duration''' identifier can take a specified number of seconds and return it in weeks/days/hours/minutes/seconds format. After a value has been returned, the new value can even be used with the identifier in order to return the number of seconds.
 
{{mirc title|$duration Identifier}}The '''$duration''' identifier can take a specified number of seconds and return it in weeks/days/hours/minutes/seconds format. After a value has been returned, the new value can even be used with the identifier in order to return the number of seconds.
 
  
 
== Synopsis ==
 
== Synopsis ==
 
<pre>$duration(seconds,N)</pre>
 
<pre>$duration(seconds,N)</pre>
 
+
<pre>$duration(timestring)</pre>
 
== Parameters ==
 
== Parameters ==
 
{{ArgsList
 
{{ArgsList
Line 10: Line 9:
 
| N | Can be either '''2''', which omits seconds from the results, or '''3''', which returns the time in hh:nn:ss format
 
| N | Can be either '''2''', which omits seconds from the results, or '''3''', which returns the time in hh:nn:ss format
 
}}
 
}}
 
+
Beginning v7.63 correctly handles negative durations.
 
== Example ==
 
== Example ==
 
Echo the formatting for '''38711810 seconds''':
 
Echo the formatting for '''38711810 seconds''':
Line 17: Line 16:
 
'''Result'''
 
'''Result'''
 
<pre>64wks 1hr 16mins 50secs</pre>
 
<pre>64wks 1hr 16mins 50secs</pre>
 +
 +
<source lang="mIRC">//echo -a $duration(38711810,2)</source>
 +
Same except does not display the seconds.
 +
'''Result'''
 +
<pre>64wks 1hr 16mins</pre>
 +
<source lang="mIRC">//echo -a $duration(38711810,3)</source>
 +
Returns the display in HH:nn:ss format, with durations longer than 1 day returning hours > 23.
 +
'''Result'''
 +
<pre>10753:16:50</pre>
  
 
Echo the formatting for converting '''64wks 1hr 16mins 50secs''' back to seconds:
 
Echo the formatting for converting '''64wks 1hr 16mins 50secs''' back to seconds:
 
<source lang="mIRC">//echo -a $duration(64wks 1hr 16mins 50secs)</source>
 
<source lang="mIRC">//echo -a $duration(64wks 1hr 16mins 50secs)</source>
 
 
'''Result'''
 
'''Result'''
 
<pre>38711810</pre>
 
<pre>38711810</pre>
 +
 +
The displayed timestring contains the time units touching their integers, so you will need to use $replace if you don't wish this:
 +
<source lang="mIRC">//echo -a This computer restarted $regsubex(foo,$duration($uptime(system,3)),/([a-z]+)/g,$chr(32) $+ \t) ago!</source>
  
 
== Compatibility ==
 
== Compatibility ==
 
{{mIRC compatibility|4.7}}
 
{{mIRC compatibility|4.7}}
 
 
== See Also ==
 
== See Also ==
 
* {{mIRC|$asctime}}
 
* {{mIRC|$asctime}}
 
* {{mIRC|$time}}
 
* {{mIRC|$time}}
{{mIRC identifier list}}
 
 
[[Category:mIRC identifiers|duration]]
 

Revision as of 00:58, 19 August 2020

The $duration identifier can take a specified number of seconds and return it in weeks/days/hours/minutes/seconds format. After a value has been returned, the new value can even be used with the identifier in order to return the number of seconds.

Synopsis

$duration(seconds,N)
$duration(timestring)

Parameters

seconds The specific number of seconds to get the formatting for
N Can be either 2, which omits seconds from the results, or 3, which returns the time in hh:nn:ss format Beginning v7.63 correctly handles negative durations.

Example

Echo the formatting for 38711810 seconds:

//echo -a $duration(38711810)

Result

64wks 1hr 16mins 50secs
//echo -a $duration(38711810,2)

Same except does not display the seconds. Result

64wks 1hr 16mins
//echo -a $duration(38711810,3)

Returns the display in HH:nn:ss format, with durations longer than 1 day returning hours > 23. Result

10753:16:50

Echo the formatting for converting 64wks 1hr 16mins 50secs back to seconds:

//echo -a $duration(64wks 1hr 16mins 50secs)

Result

38711810

The displayed timestring contains the time units touching their integers, so you will need to use $replace if you don't wish this:

//echo -a This computer restarted $regsubex(foo,$duration($uptime(system,3)),/([a-z]+)/g,$chr(32) $+ \t) ago!

Compatibility

Added: mIRC v4.7
Added on: 09 Dec 1996
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.

See Also