Suppose that I have a date range list
drlist = {{"2015-01-01", "2015-01-05"},
{"2015-01-07", "2015-01-07"},
{"2015-01-12", "2015-01-23"}}
and a range of date
sdate = "2015-01-04";
edate = "2015-01-14";
r = {sdate, edate};
to make things easy to understand, {"2015-01-04", "2015-01-14"}
in reality represent something like {"2015-01-04-00-00","2015-01-14-12-00"}
, i.e., the date start from 0:00 but end at some time of the day, say "12:00" is enough for me.
Then my question is how can I get the range of date that in r
but not in drlist
, e.g., it should be output something like:
cdrlist = {{"2015-01-05", "2015-01-06"}, {"2015-01-07", "2015-01-11"}}
and if we set endate = "2015-01-25"
, then the output should be
cdrlist = {{"2015-01-05", "2015-01-06"},
{"2015-01-07", "2015-01-11"},
{"2015-01-23", "2015-01-25"}}
It should be noted that in this case the day "25" should be contained included.
UPDATE
To clarify the confusing results I were demonstrated, let us just consider the day, the day range we have is union of closed intervals: $$ drlist=[1.0,5.5]\sqcup[7.0,7.5]\sqcup[12.0,23.5] $$ and the day range we set is just a closed interval: $$ r=[4.0,25.5] $$ thus the set $r\setminus drlist$ equals to $$ r\setminus drlist=(5.5,7)\sqcup(7.5,12)\sqcup(23.5,25.5], $$ and translated this back to day range shoulde be $$ 5-6,7-11,23-25. $$ Let me explain why $(5.5,7)$ should be $5-6$? Note that in our notation, $5-6$ represent $[5.0,6.5]$ which is exactly the interval contains $(5.5,7)$, since the $0.5$ should be understand very close to $1.0$. Also $(23.5,25.5]=(24,26)=[23,25]$ in above sense.
"2015-01-06"
and"2015-01-07"
in the output are not considered contiguous, yielding a single rangecdrlist = {{"2015-01-05", "2015-01-11"}}
. Would you clarify this please? $\endgroup$"2015-01-06"
is `"2015-01-06" at 12:00. so there is 12h to "2015-01-07". $\endgroup$drlist = {{1,2}}
which schould be intepreted as{1, 2.5}
. But if we want to take away{0, 1} (*{0,1.5}*)
then the exact result should be{1.5, 2.5}
which in "base form" is{1,2}
so even though the intersection is not empty, thedrlist
is the same. $\endgroup$