# Duration

<div class="jsdoc-content"><header>
    
        <h2><span class="attribs"><span class="type-signature"></span></span>
            <span class="ancestors"><a href="index.html">types</a>~</span>Duration<span class="signature">(months, days, nanoseconds)</span><span class="type-signature"></span></h2>
        
            <div class="class-description"><p>Represents a duration. A duration stores separately months, days, and seconds due to the fact that the number of
days in a month varies, and a day can have 23 or 25 hours if a daylight saving is involved.</p></div>
        
    
</header>


    
        

    
    </div>

## Constructor

<div class="jsdoc-content">
    

    
    <h4 class="name" id="Duration"><span class="type-signature"></span>new Duration<span class="signature">(months, days, nanoseconds)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    <p>Creates a new instance of Duration.</p>
</div>









    <h5>Parameters:</h5>
    

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>months</code></td>
            

            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>

            

            

            <td class="description last"><p>The number of months.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>days</code></td>
            

            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>

            

            

            <td class="description last"><p>The number of days.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>nanoseconds</code></td>
            

            <td class="type">
            
                
<span class="param-type">Number</span>
|

<span class="param-type">Long</span>
|

<span class="param-type">BigInt</span>


            
            </td>

            

            

            <td class="description last"><p>The number of nanoseconds.</p></td>
        </tr>

    
    </tbody>
</table>






<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/types/duration.js#L40" target="_blank" rel="noopener">types/duration.js, line 40</a></p></div>




















    
    

    

    

    

    

    

    

    
        </div>

## Members

<div class="jsdoc-content">

        
            
<h4 class="name" id="days"><span class="type-signature">(readonly) </span>days<span class="type-signature"> :Number</span></h4>




<div class="description">
    <p>Gets the number of days</p>
</div>



    <h5>Type:</h5>
    <ul>
        <li>
            
<span class="param-type">Number</span>


        </li>
    </ul>





<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/types/duration.js#L134" target="_blank" rel="noopener">types/duration.js, line 134</a></p></div>






        
            
<h4 class="name" id="months"><span class="type-signature">(readonly) </span>months<span class="type-signature"> :Number</span></h4>




<div class="description">
    <p>Gets the number of months</p>
</div>



    <h5>Type:</h5>
    <ul>
        <li>
            
<span class="param-type">Number</span>


        </li>
    </ul>





<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/types/duration.js#L121" target="_blank" rel="noopener">types/duration.js, line 121</a></p></div>






        
            
<h4 class="name" id="nanoseconds"><span class="type-signature">(readonly) </span>nanoseconds<span class="type-signature"> :Long</span></h4>




<div class="description">
    <p>Gets the number of nanoseconds</p>
</div>



    <h5>Type:</h5>
    <ul>
        <li>
            
<span class="param-type">Long</span>


        </li>
    </ul>





<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/types/duration.js#L147" target="_blank" rel="noopener">types/duration.js, line 147</a></p></div>






        
    

    
        </div>

## Methods

<div class="jsdoc-content">

        
            

    

    
    <h4 class="name" id="toBuffer"><span class="type-signature"></span>toBuffer<span class="signature">()</span><span class="type-signature"> &rarr; {Buffer}</span></h4>
    

    



<div class="description">
    <p>Serializes the duration and returns the representation of the value in bytes.</p>
</div>













<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/types/duration.js#L159" target="_blank" rel="noopener">types/duration.js, line 159</a></p></div>















<h5>Returns:</h5>

        


<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Buffer</span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="toString"><span class="type-signature"></span>toString<span class="signature">()</span><span class="type-signature"> &rarr; {string}</span></h4>
    

    



<div class="description">
    <p>Returns the string representation of the value.</p>
</div>













<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/types/duration.js#L187" target="_blank" rel="noopener">types/duration.js, line 187</a></p></div>















<h5>Returns:</h5>

        


<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">string</span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id=".fromBuffer"><span class="type-signature">(static) </span>fromBuffer<span class="signature">(buffer)</span><span class="type-signature"> &rarr; {Duration}</span></h4>
    

    



<div class="description">
    <p>Creates a new Duration instance from the binary representation of the value.</p>
</div>









    <h5>Parameters:</h5>
    

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>buffer</code></td>
            

            <td class="type">
            
                
<span class="param-type">Buffer</span>


            
            </td>

            

            

            <td class="description last"></td>
        </tr>

    
    </tbody>
</table>






<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/types/duration.js#L230" target="_blank" rel="noopener">types/duration.js, line 230</a></p></div>















<h5>Returns:</h5>

        


<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Duration</span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id=".fromString"><span class="type-signature">(static) </span>fromString<span class="signature">(input)</span><span class="type-signature"> &rarr; {Duration}</span></h4>
    

    



<div class="description">
    <p>Creates a new Duration instance from the string representation of the value.</p>
</div>









    <h5>Parameters:</h5>
    

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>input</code></td>
            

            <td class="type">
            
                
<span class="param-type">String</span>


            
            </td>

            

            

            <td class="description last"><p>Accepted formats:</p>
<ul>
<li>multiple digits followed by a time unit like: 12h30m where the time unit can be:
<ul>
<li><code>y</code>: years</li>
<li><code>mo</code>: months</li>
<li><code>w</code>: weeks</li>
<li><code>d</code>: days</li>
<li><code>h</code>: hours</li>
<li><code>m</code>: minutes</li>
<li><code>s</code>: seconds</li>
<li><code>ms</code>: milliseconds</li>
<li><code>us</code> or <code>µs</code>: microseconds</li>
<li><code>ns</code>: nanoseconds</li>
</ul>
</li>
<li>ISO 8601 format:  <code>P[n]Y[n]M[n]DT[n]H[n]M[n]S or P[n]W</code></li>
<li>ISO 8601 alternative format: <code>P[YYYY]-[MM]-[DD]T[hh]:[mm]:[ss]</code></li>
</ul>
<p>Duration can be made negative by adding <code>-</code> at the beginning of the input</p></td>
        </tr>

    
    </tbody>
</table>






<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/types/duration.js#L265" target="_blank" rel="noopener">types/duration.js, line 265</a></p></div>















<h5>Returns:</h5>

        


<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Duration</span>


    </dd>
</dl>

    




    <h5>Examples</h5>
    
        <p class="code-caption">From formatted string</p>
    
    <div class="highlight-javascript notranslate"><div class="highlight"><pre>let date = fromString("4mo7d20ns");  // 1 month, 7 days, 20 nanoseconds</pre></div></div>

        <p class="code-caption">From ISO 8601</p>
    
    <div class="highlight-javascript notranslate"><div class="highlight"><pre>let date = fromString("P2DT5M");     // 2 days, 5 minutes</pre></div></div></div>
