www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15137] New: core.time: Support Duration/Duration and


          Issue ID: 15137
           Summary: core.time: Support Duration/Duration and
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: thecybershadow gmail.com
                CC: issues.dlang jmdavisProg.com

Currently porting some D1 code to D2, and some of the D1 code is quite annoying
as rewritten to use core.time.

Example 1:

auto units = [
    "days" : TicksPerDay,
    "hours" : TicksPerHour,
    "seconds" : TicksPerSecond,
d_time d = 1234567890;
foreach (name, duration; units)
    writefln("%d %s", d/duration, name);

Converting between time units when you don't know the unit during compilation
using core.time is excessively verbose - you have to use something like:
duration.total!"hnsecs" / unit.total!"hnsecs". This is also leaking a low-level
detail (that Duration is internally represented as hnsecs).

Example 2:

fiveMinuteTotals[delta % TicksPerDay / (5*TicksPerMinute)]++;

This calculates collective frequency when during the day events occur, with
five-minute granularity. With core.time, this becomes something like...

fiveMinuteTotals[delta.split!("days", "hnsecs").hnsecs /

I really don't see any reason why Duration should not support binary / and %
with two Durations.

Oct 02 2015