title: Split overlapping date time intervals into non-overlapping intervals, within values of an identifier
body: <p>I have an exact problem with this question <a href="https://stackoverflow.com/questions/55836442/split-overlapping-intervals-into-non-overlapping-intervals-within-values-of-an">Split overlapping intervals into non-overlapping intervals, within values of an identifier</a> using R data.table, but with an additional issue that my intervals are date time instead of integers. My identifier is the id column. In the original data, I have overlapping time periods, and I want to split them into all non-overlapping periods for each id.</p>
  <p>Have:</p>
  <pre><code>dt &lt;- data.table(id = c(1, 1, 1),
                   start = c(&quot;1970-01-10 06:01:16&quot;, &quot;1970-01-10 12:01:16&quot;, &quot;1970-01-10 09:34:49&quot;),
                   end = c(&quot;1970-01-10 12:01:16&quot;, &quot;1970-01-10 17:01:16&quot;, &quot;1970-01-11 07:49:48&quot;),
                   value = c(1, 0, 3))
  
  id  start                end                    value
  1   1970-01-10 06:01:16  1970-01-10 12:01:16    1
  1   1970-01-10 12:01:16  1970-01-10 17:01:16    0
  1   1970-01-10 09:34:49  1970-01-11 07:49:48    3
  </code></pre>
  <p>Want:</p>
  <pre><code>id  start                end                    value
  1   1970-01-10 06:01:16  1970-01-10 09:34:49    1
  1   1970-01-10 09:34:49  1970-01-10 12:01:16    1
  1   1970-01-10 12:01:16  1970-01-10 17:01:16    0
  1   1970-01-10 09:34:49  1970-01-10 12:01:16    3
  1   1970-01-10 12:01:16  1970-01-10 17:01:16    3
  1   1970-01-10 17:01:16  1970-01-11 07:49:48    3
  </code></pre>
  <p>Appreciate any help!</p>