title: Given two intervals, how to return logical true false if intervals overlap?
body: <p>I'm trying to work out whether two different date ranges overlap and return a TRUE/FALSE where they do, which will allow me to successfully filter the data I'm interested in. I was trying to use lubridate intervals and the %within% which basically checks whether a date falls within a period. In the example below, I was checking whether the <code>started_fishing</code> date and the <code>finished_fishing</code> date fell within the period defined by the <code>start_of_fishing_season</code> and <code>end_of_fishing_season</code>.</p>
  <p>This approach doesn't work. As, although in the example below the dates don't fall within the period, if we assume we are fishing constantly from the <code>started_fishing</code> date to the <code>finished_fishing</code> date then some of the dates would fall within the fishing season.</p>
  <p>I've inserted the true/false column to indicate what a correct output should look like.</p>
  <p>I'm guessing perhaps what I need to do is to create a sequence from <code>started_fishing</code> and <code>finished_fishing</code> and then check each date against fishing season dates? Hope this is clear enough, any help appreciated.</p>
  <p>Ideally fixing this in lubridate (which isn't shown below) would be great.</p>
  <pre><code>
  deployment = data.frame(start_of_fishing_season = c(as.POSIXct(&quot;2019-10-16&quot;, tz = &quot;UTC&quot;),
                                                      as.POSIXct(&quot;2019-10-16&quot;, tz = &quot;UTC&quot;)),
                          end_of_fishing_season = c(as.POSIXct(&quot;2020-05-01&quot;, tz = &quot;UTC&quot;),
                                                    as.POSIXct(&quot;2020-05-01&quot;, tz = &quot;UTC&quot;)),
                          started_fishing = c(as.POSIXct(&quot;2019-06-12 15:45:00&quot;, tz = &quot;UTC&quot;),
                                              as.POSIXct(&quot;2019-06-12 15:45:00&quot;, tz = &quot;UTC&quot;)),
                          finished_fishing = c(as.POSIXct(&quot;2021-03-24 15:45:00&quot;, tz = &quot;UTC&quot;),
                                               as.POSIXct(&quot;2019-08-13 15:45:00&quot;, tz = &quot;UTC&quot;)),
                          fishing_overlaps = c(TRUE,FALSE))
  
  
  deployment
  #&gt;   start_of_fishing_season end_of_fishing_season     started_fishing
  #&gt; 1              2019-10-16            2020-05-01 2019-06-12 15:45:00
  #&gt; 2              2019-10-16            2020-05-01 2019-06-12 15:45:00
  #&gt;      finished_fishing fishing_overlaps
  #&gt; 1 2021-03-24 15:45:00             TRUE
  #&gt; 2 2019-08-13 15:45:00            FALSE
  
  </code></pre>