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

Message ListMessage List     Post MessagePost Message

  Chart::chartTime retrives wrong time
Posted by Medic89 on Mar-04-2024 23:36
Hello Peter,

since last week (I guess its because this february had 29 days) Chart::chartTime retrieves the correct time, but its always 24 hours earlier. This is how I get the current time:

CTime CurrentTime = CTime::GetCurrentTime();
return Chart::chartTime(CurrentTime.GetYear() - 1969, CurrentTime.GetMonth(), CurrentTime.GetDay(), CurrentTime.GetHour(), CurrentTime.GetMinute(), CurrentTime.GetSecond());

I use the same function to display the time in my app, but without the Chart::chartTime function. Then the day is correct, but with the function above, one day is "missing".

  Re: Chart::chartTime retrives wrong time
Posted by Peter Kwan on Mar-05-2024 04:46
Hi Medic89,

In your code, the year parameter is set to "CurrentTime.GetYear() - 1969". I think it should be "CurrentTime.GetYear()". There is no need to minus 1969. The "minus 1969" may change the leap year into a non-leap year, causing the issue.

Best Regards
Peter Kwan

  Re: Chart::chartTime retrives wrong time
Posted by Medic89 on Mar-05-2024 18:51
I tried, but then my chart axis shows a "-1:-1" as a time stamp instead of "11:00" for example. I guess the problem is, that the Chart::chartTime function starts at the year 0, while CTime starts in the year 1970?

  Re: Chart::chartTime retrives wrong time
Posted by Peter Kwan on Mar-05-2024 21:04
Hi Medic89,

It should should not matter when does the epoch begin. As long as you pass the actual year (which is 2024), it is OK.

Your code does not indicate what is the data type of the return value of your function. According to ChartDirector documentation, the chartTime returns a "double" value, so the return value should be "double". If your function is declared to return an "int", this will cause the problem you see.

If the above still cannot solve the problem, please print out the date/time to the Visual Studio debug window using the TRACE macro, so we can see if they are as expected:

CTime CurrentTime = CTime::GetCurrentTime();

// Print out what is CurrentTime
TRACE("CTime: y=%d, m=%d, d=%d, h=%d, n=%d, d=%dn", CurrentTime.GetYear(),
    CurrentTime.GetMonth(), CurrentTime.GetDay(), CurrentTime.GetHour(),
    CurrentTime.GetMinute(), CurrentTime.GetSecond());

double t= Chart::chartTime(CurrentTime.GetYear(), CurrentTime.GetMonth(),
    CurrentTime.GetDay(), CurrentTime.GetHour(), CurrentTime.GetMinute(),
    CurrentTime.GetSecond());

// Print out what is chart Time
TRACE("chartTime: t=%f => %sn", t, c->formatValue(time, "{value|yyyy-mm-dd hh:nn:ss}"));

Please let me know what is the result.

Best Regards
Peter Kwan

  Re: Chart::chartTime retrives wrong time
Posted by Medic89 on Mar-06-2024 00:45
Hello Peter,

I think I found the problem, i have a function that sets the starting time of the chart to be a littlebit in Front of the first event. However, I converted the double number from chartTime back into a CTime object, because I wanted to know if a certain chartTime value is at a full hour (11:00 for example).

  Re: Chart::chartTime retrives wrong time
Posted by Medic89 on Mar-06-2024 01:23
Appart from that, I have to translate time values from chartTime back to datetimepickers in MFC. That's why I used the CTime format.

  Re: Chart::chartTime retrives wrong time
Posted by Peter Kwan on Mar-06-2024 11:42
Hi Medic89,

For a chartTime value, if you need to check for whole hours, you can use:

// One hour has 60 x 60 = 3600 seconds. A whole hour must be an exact multiple of 3600
bool isWholeHour = (fmod(t, 3600) == 0);

If you want to get the yyyy-mm-dd hh:nn:ss.fff of a chartTime value, you can use:

// millisecond is the fractional part
double fff = fmod(t, 1) * 1000;

// remove the millisecond part
__int64 t2 = (__int64)t;

// second of minute.
int ss = (int)(t2 % 60);
t2 /= 60;

// minute of hour.
int nn = (int)(t2 % 60);
t2 /= 60;

// hour of day
int hh = (int)(t2 % 24);
t2 /= 24;

int yyyymmdd = Chart::getChartYMD(t2);

dd = yyyymmdd % 100;
mm = (yyyymmdd / 100) % 100;
yyyy = yyyymmdd / 10000;


Best Regards
Peter Kwan