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

m (PatrolBot moved page $duration identifier - mIRC to mirc/identifiers/$duration: per new naming convention)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
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.
 +
 
 +
Accept negative value
  
 
== Synopsis ==
 
== Synopsis ==
 
<pre>$duration(seconds,N)</pre>
 
<pre>$duration(seconds,N)</pre>
 
+
<pre>$duration(timestring)</pre>
 
== Parameters ==
 
== Parameters ==
 
{{ArgsList
 
{{ArgsList
Line 9: Line 11:
 
| 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 16: Line 18:
 
'''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]]
 

Latest revision as of 19:47, 22 January 2022

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.

Accept negative value

Synopsis[edit]

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

Parameters[edit]

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[edit]

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[edit]

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[edit]