[Issue 15137] New: core.time: Support Duration/Duration and Duration%Duration

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Oct 2 08:00:42 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=15137

          Issue ID: 15137
           Summary: core.time: Support Duration/Duration and
                    Duration%Duration
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: thecybershadow at gmail.com
                CC: issues.dlang at 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 /
5.minutes.total!"hnsecs"]++;

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

--


More information about the Digitalmars-d-bugs mailing list