On Wed, 04 Jun 2014 09:12:06 +0200
Sönke Ludwig via Digitalmars-d <[email protected]> wrote:
> Just a minor note: What about just .only!"minutes", analogous
> .total!"minutes"? Removing both the .minutes shortcut and the short
> "get" method, pretty heavily increases verbosity, so shortening
> "getOnly" might be a good idea.
Actually, after some further discussion, I think that we've decided to remove
get/getOnly entirely. Instead, we'll have a function called split which splits
the Duration among the units that you request (rather than just one). I'll be
updating the current pull request with those changes shortly, so we may not
end up with exactly what I have at the moment, but these are the currently
proposed documentation examples for split:
{
auto d = dur!"days"(12) + dur!"minutes"(7) + dur!"usecs"(501223);
long days;
int seconds;
short msecs;
d.split!("days", "seconds", "msecs")(&days, &seconds, &msecs);
assert(days == 12);
assert(seconds == 7 * 60);
assert(msecs == 501);
auto splitStruct = d.split!("days", "seconds", "msecs")();
assert(splitStruct.days == 12);
assert(splitStruct.seconds == 7 * 60);
assert(splitStruct.msecs == 501);
auto fullSplitStruct = d.split();
assert(fullSplitStruct.weeks == 1);
assert(fullSplitStruct.days == 5);
assert(fullSplitStruct.hours == 0);
assert(fullSplitStruct.minutes == 7);
assert(fullSplitStruct.seconds == 0);
assert(fullSplitStruct.msecs == 501);
assert(fullSplitStruct.usecs == 223);
assert(fullSplitStruct.hnsecs == 0);
assert(d.split!"minutes"().minutes == d.total!"minutes");
}
{
auto d = dur!"days"(12);
assert(d.split!"weeks"().weeks == 1);
assert(d.split!"days"().days == 12);
assert(d.split().weeks == 1);
assert(d.split().days == 5);
}
{
auto d = dur!"days"(7) + dur!"hnsecs"(42);
assert(d.split!("seconds", "nsecs")().nsecs == 4200);
}
I think that it will be a definite improvement.
- Jonathan M Davis