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
Comment #2 by github-bugzilla — 2015-10-03T20:40:43Z
Commits pushed to master at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/809b40a9b110b652ba4539679c292fbe068d5cab core.time: Implement Duration % Duration Fixes issue 15137 https://github.com/D-Programming-Language/druntime/commit/e02d47c8886bcf8bc969789c4dd1dbed4fdb90e8 core.time: Implement Duration / Duration Fixes issue 15137 https://github.com/D-Programming-Language/druntime/commit/8ddfb8dd711cc503fbe371ac7c4c26ed5caf1d0b Merge pull request #1401 from CyberShadow/pull-20151002-151147 fix Issue 15137 - core.time: Support Duration/Duration and Duration%Duration
Comment #3 by github-bugzilla — 2015-10-04T18:19:26Z