D-Programming-Language/druntime — pull request #825 by jmdavis (2014-06-04 08:52:57+00:00)
Title: Fix for 12837: Duration's get and individual unit getters are bug-prone.

Experience has shown that most people (at least some of who don't read
the documentation) seem to expect that get and the indivdual getters
return what total returns, causing bugs. So, this commit adds partial to
replace get (leaving get as deprecated) and deprecates the individual
unit getters, forcing folks to use total or partial explicitly. It's
likely that most code that will have to change because of these changes
is broken anyway, so this will catch bugs.

Okay. Here's another go at it. Based on the discussion in the previous pull, I renamed `getOnly` to `partial`, since while it's a bit obtuse, it goes well with `total`, and it's shorter than `getComponent`, which gets a bit long when you have to add the template argument to it. I also adjusted the deprecation messages based on David's comments.

I feel a bit funny about `partial` being a property, since it takes a template argument, but `total` has been that way for some time now, and their names are property names, not function names. But we could change them both to be non-property functions without breaking code (it just would make their names a bit odd, since they're nouns rather than verbs).

Regardless, I think that these changes (or something very close to them) need to be made, since the current situation with the getters on `Duration` has turned out to be overly error-prone. Fortunately, it's likely the case that most code which needs to convert a `Duration` to units wants `total`, so while some code is bound to have to be changed for this, it's probably either relatively little code, or it's mostly code that should have been using `total` anyway.

Once these changes have been approved and merged, I'll create a second pull request for std.datetime to fix the one function that will get deprecation warnings thanks to this.