I’m messing with core.time.Durations – in particular, I’m trying to properly get number of full minutes in “2 days and 1 hour” Duration. As it have cleared, get!"minutes" returns number of minutes without hours, days and weeks (e.g. 0 in this case), so it’s inappropriate for me, because I expect answer of 2940.
I’ve looked into sources and found core.time.getUnitsFromHNSecs function, which does exactly what I need, but it’s private to core.time and uses private field _hnsecs of Duration objects.
Of course, it’s possible to do
long minutes_in_duration(Duration d) {
return (d.get!"minutes"() + d.get!"hours"() * 60 +
d.get!"days"() * 24 * 60 + d.get!("weeks") * 7 * 24 * 60);
}
but this is clumsy as hell. Is there better way to do the same thing without scattering away Duration‘s guts?
More thorough reading through source revealed overlooked
.total!"unit"property, which does exactly what it should.