Bug 15137 – core.time: Support Duration/Duration and Duration%Duration
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-10-02T15:00:00Z
Last change time
2015-10-04T18:19:26Z
Keywords
pull
Assigned to
nobody
Creator
dlang-bugzilla
Comments
Comment #0 by dlang-bugzilla — 2015-10-02T15:00:42Z
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.
Comment #1 by dlang-bugzilla — 2015-10-02T15:43:29Z