I'm guessing this has been discussed and there's a good reason, but I haven't been able to find it.
It seems odd to me that you can't create a zero-duration TimeSpan . It seems to be a consequence of the combination of
- the constraint that
start < stop
- computing the duration at
stop-start
Are both those necessarily true? It seems like you could either relax the constraint such that start <= stop, or compute the duration as stop-start-1.
I can think of 3 different semantics you could attach to a TimeSpan:
start and stop mark points on a continuous timeline, and they happen to be quantized to 1ns, so TimeSpan(x, y) represents the span [x,y), where the endpoint is infinitesimally close to y on the timeline. In this interpretation:
duration = stop - start
TimeSpan(x, y) and TimeSpan(y, z) are contiguous (assuming x < y < z).
stop >= start
start and stop are indices referring to the 1ns chunks of time that is occupied by this TimeSpan. This can be further subdivided
a. The range is inclusive, (like the julia range 4:6 which represents [4,5,6]). This is explicitly ruled-out in the docs which say it represents "the interval [start, stop)", but isn't an unreasonable semantic, and would imply:
- duration = stop - start + 1
- TimeSpan(x, y) and TimeSpan(y+1, z) are contiguous
- stop >= start-1 (it seems a little weird to represent an empty span with t, t-1 but that's how range does it)
b. The range is exclusive, which implies:
- duration = stop - start
- TimeSpan(x, y) and TimeSpan(y, z) are contiguous.
- stop >= start
1 and 2b are in practice the same thing, and are what's implemented. They are internally consistent (e.g.duration(TimeSpan(x, z)) == duration(TimeSpan(x, y)) + duration(TimeSpan(y, z)), and overlaps is false).
Most of this was just me thinking through the details to make sure I understood. I'm still left with the question though of why can't stop == start to represent a zero-length span?
(side note - it makes sense that 1 and 2b would be the same, as 1 is just the limit of 2b as the chunk size goes to 0)
I'm guessing this has been discussed and there's a good reason, but I haven't been able to find it.
It seems odd to me that you can't create a zero-duration
TimeSpan. It seems to be a consequence of the combination ofstart < stopstop-startAre both those necessarily true? It seems like you could either relax the constraint such that
start <= stop, or compute the duration asstop-start-1.I can think of 3 different semantics you could attach to a
TimeSpan:startandstopmark points on a continuous timeline, and they happen to be quantized to 1ns, soTimeSpan(x, y)represents the span[x,y), where the endpoint is infinitesimally close toyon the timeline. In this interpretation:duration = stop - startTimeSpan(x, y)andTimeSpan(y, z)are contiguous (assumingx < y < z).stop >= startstartandstopare indices referring to the 1ns chunks of time that is occupied by this TimeSpan. This can be further subdivideda. The range is inclusive, (like the julia range
4:6which represents[4,5,6]). This is explicitly ruled-out in the docs which say it represents "the interval [start, stop)", but isn't an unreasonable semantic, and would imply:-
duration = stop - start + 1-
TimeSpan(x, y)andTimeSpan(y+1, z)are contiguous-
stop >= start-1(it seems a little weird to represent an empty span witht, t-1but that's howrangedoes it)b. The range is exclusive, which implies:
-
duration = stop - start-
TimeSpan(x, y)andTimeSpan(y, z)are contiguous.-
stop >= start1 and 2b are in practice the same thing, and are what's implemented. They are internally consistent (e.g.
duration(TimeSpan(x, z)) == duration(TimeSpan(x, y)) + duration(TimeSpan(y, z)), andoverlapsis false).Most of this was just me thinking through the details to make sure I understood. I'm still left with the question though of why can't
stop == startto represent a zero-length span?(side note - it makes sense that 1 and 2b would be the same, as 1 is just the limit of 2b as the chunk size goes to 0)