5
$\begingroup$

I want to make a time interval slider with an initial setting of (10:00:00 Mar. 8 2015, 12:30:00 Mar. 8 2015) and which varies from 00:00:00 Mar. 8 2015 to 22:30:00 Mar. 8 2015 with a granularity of 5 Minutes.

I tried using IntervalSlider in Mathematica 10 like this:

IntervalSlider[{DateString[{2015, 3, 8, 10, 0, 0.}], 
      DateString[{2015, 3, 8, 12, 30, 0.}]}, {DateObject[{2015, 3, 8, 0, 
        0, 0.}], DateObject[{2015, 3, 8, 22, 30, 0.}], 
      Quantity[5, "Minutes"]}] 

but it doesn't work. Any ideas?

$\endgroup$
6
$\begingroup$

You will need work with an interval slider in terms of AbsoluteTime values because such sliders only work with numeric objects. Here is a demonstration where a interval slider has the behavior you want.

With[{
  min0 = AbsoluteTime @ DateObject[{2015, 3, 8, 10, 0, 0.}],
  max0 = AbsoluteTime @ DateObject[{2015, 3, 8, 12, 30, 0.}],
  minT = AbsoluteTime @ DateObject[{2015, 3, 8, 0, 0, 0.}],
  maxT = AbsoluteTime @ DateObject[{2015, 3, 8, 22, 30, 0.}]}, 
  Manipulate[
    DateString /@ span,
    {{span, {min0, max0}, "Interval"}, minT, maxT, 5 60, 
      ControlType -> IntervalSlider}]]

demo

$\endgroup$
1
  • $\begingroup$ Cool! It is done. $\endgroup$
    – hptru64
    Apr 1 '15 at 9:10
2
$\begingroup$

In version 10.1, try this:

Manipulate[
   TimelinePlot[
       {Interval[{ToString[myBegin], ToString[myEnd]}] -> "My range"},
       PlotRange -> {DateObject[{1940}], DateObject[{2020}]},
     Ticks -> {DateRange["1940", "2020", Quantity[5, "Years"]]}
  ],
 {{myBegin, 1950, "Begin"}, 1950, 2014, 1},
 {{myEnd, 1960, "End"}, myBegin, 2015, 1}]
$\endgroup$
3
  • $\begingroup$ +1, but note as Begin slider increases, the DateTicks start to overlap. Maybe you can answer my Q: mathematica.stackexchange.com/questions/78821/… $\endgroup$ Apr 1 '15 at 22:33
  • $\begingroup$ @alancalvitti I think there must be a bug in TimelinePlot which prevents the "obvious" implementation of PlotRange. (I just got 10.1 an hour ago, so haven't explored all the power and limitations of TimelinePlot. However, Ticks->All in my example prevents overlapping (but marks by seconds). $\endgroup$ Apr 1 '15 at 22:36
  • $\begingroup$ @alancalvitti I figured it out. See my revised solution. $\endgroup$ Apr 1 '15 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.