Closed Mordil closed 7 months ago
I'm not sure this is entirely possible at the TimeDifference
level… How would TimeDifference
know if one of the intermediate hours was longer or shorter than normal?
Edit...
To give a concrete example: Let's say you ask for the number of days between two consecutive days. You get back a TimeDifference
of 1 day. But if you then ask for how many hours that is, it can't tell you. It might be 23, 24, or 25 depending on which days they are and whether there's a daylight saving transition between them (or not). It gets worse if the days are further apart because there might be multiple transitions.
I can see the appeal of something like this though. I'll think about it.
That’s all one can ask! If it doesn’t make sense (or impossible to represent) I understand
I think the solution here is to compute two differences:
let diff = start - end // hour: 1 minute: 3
let minuteDiff = start.differenceInWholeMinutes(to: end) // minute: 63
@Mordil is that sufficient for your use-cases?
I think the 2nd API call is more of exactly what I was looking for, for the original use case
Right now
TimeDifference
provides concreteInt
properties of each unit component of a given difference, which leaves users to implement a way of getting a total of a specific unit.For example, to find the total number of minutes between two TimePeriods (such as an event with a start/end), you need to do:
I'd be appreciative to have an API like the following:
I understand this can get very problematic at higher & lower precision, maybe a first release could just be seconds/minutes/hours?