<div dir="ltr">thanks!</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Feb 14, 2014 at 2:14 PM, Jonathan M Davis <span dir="ltr"><<a href="mailto:jmdavisProg@gmx.com" target="_blank">jmdavisProg@gmx.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Thursday, February 13, 2014 23:37:13 Timothee Cour wrote:<br>
> Is there a function to do this?<br>
> If not and I/someone writes it, is there interest to add it to std.datetime?<br>
><br>
> Duration t = ...;<br>
> <a href="http://t.to" target="_blank">t.to</a>!string => 5 secs, 889 ms, and 811 ìs<br>
> <a href="http://t.round.to" target="_blank">t.round.to</a>!string    => 5 secs<br>
><br>
> t=...;<br>
> <a href="http://t.to" target="_blank">t.to</a>!string => 889 ms, and 811 ìs<br>
> <a href="http://t.round.to" target="_blank">t.round.to</a>!string    => 889 secs<br>
><br>
> Use case: shorter logs.<br>
<br>
</div>There is no function for that, and no one's ever asked for anything like it,<br>
so I don't know how worthwhile it is to add. However, one possible<br>
implementation would be<br>
<br>
auto roundToLargest(Duration d)<br>
{<br>
    foreach(units; TypeTuple!("weeks", "days", "hours", "minutes",<br>
                              "seconds", "msecs", "usecs"))<br>
    {<br>
        immutable value = d.total!units();<br>
        if(value != 0)<br>
            return dur!units(value);<br>
    }<br>
<br>
    return d;<br>
}<br>
<span class="HOEnZb"><font color="#888888"><br>
- Jonathan M Davis<br>
<br>
</font></span></blockquote></div><br></div>