Skip to content

Should we allow zero-duration TimeSpans? #55

Description

@ssfrr

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:

  1. 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
  1. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions