ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  XY charting with daylight savings time
Posted by Brian Struhammer on Jun-18-2015 04:15
Attachments:
Hi Peter,

I spoke to you about this issue awhile ago, and I thought I had it working, but I guess not.
I?m creating an XY chart with the x and y axes reversed, to show a timeline of our instrumentation processing. Attached is the output chart, which contains a simple 1 item timeline, with what is supposed to be a 1 hour and 7 minute box in green followed by a 1 second box in blue. The timeline is spanning a daylight savings transition at 2 AM. Unfortunately, the timeline is coming out 1 hour longer than it should.

I?m making the following calls to set up the chart:

   c.yAxis().setDateScale(Chart.CTime(dtSchedChartStartTime),
      Chart.CTime(dtNewEnd));

and

   viewer.setFullRange("y",  Chart.CTime(dtSchedChartStartTime), Chart.CTime(dtNewEnd));

where

   dtSchedChartStartTime  = 3/8/2015 1:39:37 AM
   dtNewEnd  = 3/8/2015 3:47:01 AM

After the chart is drawn, I then perform the following:

   DateTime viewPortStartDate = Chart.NTime(viewer.getValueAtViewPort("y",
      viewer.ViewPortLeft));
   DateTime viewPortEndDate = Chart.NTime(viewer.getValueAtViewPort("y",
      viewer.ViewPortLeft   + viewer.ViewPortWidth));

   TimeSpan tsViewStartToEnd = viewPortEndDate - viewPortStartDate;

where:

   viewPortStartDate = 3/8/2015 1:39:37 AM
   viewPortEndDate = 3/8/2015 3:47:01 AM
   tsViewStartToEnd.TotalSeconds = 7644

It?s interesting that viewPortEndDate is correct, even though the chart is 1 hour longer, and tsViewStartToEnd.TotalSecond is one hour longer than it should be (though that part is easy enough to correct, since I can tell when the DST occurs).

The planned finish time at the top of the chart is correct, since that is handled behind-the-scenes, as is the chart labels at the bottom, which show the skip from 2 to 3 AM.

So the question is why is the chart 1 hour than it should be, even though I?m passing in 3/8/2015 3:47:01 AM for the end time to the setDateScale function? It doesn?t seem to matter whether I pass in that, or a 3/8/2015 2:47:01 AM, I still get the same results.

One thought I had was that even though the setDateScale is getting passed in the correct end time, maybe when I drew the box layer for the green portion, I passed in the wrong value, so that the chart was extended. Therefore, I looked at the following call,

   iLayer = c.addBoxLayer(Chart.CTime(dtTempStart), Chart.CTime(dtTempEnd),
      incubPatternColor, "");

but dtTempEnd was also set to 3/8/2015 3:47:01 AM.

Let me know if you need anymore information.

Thanks,
Brian
Timeline.png

  Re: XY charting with daylight savings time
Posted by Peter Kwan on Jun-19-2015 01:39
Hi Brian,

ChartDirector always use "clock time". It assumes one day has 24 hours, and the time
difference between two consecutive hours on a clock must be 3600 seconds, and so on.
It does not use physical time, which needs to take into account that the clock can jump
1 hour forward, and can also move backwards, and that some date/time specified as
(yyyy-mm-dd hh:nn:ss) may not be unique (that is, there can be two instance with
exactly the same yyyy-mm-dd hh:nn:ss due to the clock moving backwards).

One issue with using physical time is that it is difficult to determine which hour needs to
adjust for historical time. It is because the DST rules are different in every country, and
it can change. In some countries it can change very frequently. I believe on Windows,
Microsoft will update the operating system with the latest DST rule (assuming the system
has enabled receiving updates from Microsoft), so that the OS can adjust the realtime
clock correctly. But it is only for the current time, not historical time. which may be using
a different rule.

For your case, is it that the x-axis labels are determine with your own code? I am
thinking, if the chart is drawn with ChartDirector, it should use 1:00, 2:00, 3:00 and so
on. It should put the data points at the correct positions (eg, the point at 3:47 will be
put at 3:47). However, the axis length may not reflect the physical duration.

If your code can determine how to adjust for the DST hour and the axis labels, and can
compute the physical duration, you can configure the chart as:

viewer.setFullRange("y",  Chart.CTime(dtSchedChartStartTime),
Chart.CTime(dtSchedChartStartTime) + durationInSeconds);

The position of your data points must also be specified as the duration from the
dtSchedChartStartTime. So instead of using dtTempEnd, you can use

Chart.CTime(dtSchedChartStartTime) + secondElapsedSinceStartTimeForDtTempEnd

In other words, all time can be specified as the physical duration since the reference time
dtSchedChartStartTime.

Regards
Peter Kwan

  Re: XY charting with daylight savings time
Posted by Brian Struhammer on Jun-24-2015 01:49
Thanks Peter. That makes sense.