Problem with "Time::getCurrentTime()"


#1

Hi,
This method “juce::Time::getCurrentTime()” doesn’t return current time. The time it returns would be either 30 minutes behind the machine time or ahead of it, which again is not consistent.

I have seen this problem with juce_1.39 and juce_1.45 on both mac and pc, am not sure whether it exists in juce_1.46. I have used c calls instead of this call in my code. 

Am attaching a piece of the code which could be use full. This would print the current system time.

#include <stdio.h>
#include <time.h>

int main ()
{
  time_t rawtime;
  struct tm * timeinfo;
  char buffer [80];

  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  //printf("%ld time", rawtime);
 strftime (buffer,80,"Now is %I:%M%p.",timeinfo);
 puts (buffer);

  return 0;
}

regards,
vishvesh


#2

Well the juce code also uses standard time functions internally, and I wasn’t aware of any problems with it… It uses gettimeofday and localtime to sort out the timezone - you can see for yourself in juce_Time.cpp.

You’re not changing the time zone after the app has started, are you? Juce does cache some info to make the calculations quicker, but I can’t see anything else that’s obviously wrong with the code…


#3

hi,

[quote]
You’re not changing the time zone after the app has started, are you? Juce does cache some info to make the calculations quicker, but I can’t see anything else that’s obviously wrong with the code…[/quote]

Am not changing time zone after the application has started. Is it possible that the data that juce caches could be out-dated. I ll look into the code and system setting and let you as soon as possible.


#4

Thanks - I’m surprised to hear about there being timezone issues, because that code has been unchanged for so long, and there are plenty of users around the world who should have spotted an error by now!

Have to admit that living in the UK with GMT+0 is probably the worst place for debugging timezone code!


#5

Sorry for the false alarm, the problem is not with “getCurrentTime ()” it’s with “Time::toString()” method which doesn’t convert the time into string properly, am trying to fix the issue and I ll let you know as soon as i fix it


#6

Thanks - I suspected that was the case. But even that uses the standard unix time methods, so I’m stumped as to why it’d be wrong.


#7

The problem is here

int Time::getMinutes() const throw()
{
    return extendedModulo (millisSinceEpoch / 60000, 60);
}

The problem is with the value of “millisSinceEpoch”, which has stumped me too. Still working on it, hopefully I should be able to find it out.


#8

doh! Of course, it should be:

[code]int Time::getMinutes() const throw()
{
struct tm t;
millisToLocal (millisSinceEpoch, t);
return t.tm_min;
}

[/code]

Sorry, I should have noticed that sooner!


#9

It was not a problem, I was free, but please take look at “getSeconds()” and “getMilliseconds()”, these two methods have similar implementation as “getMinutes()”.

It was a pleasure helping the leader. :smiley:


#10

Thanks! Those other methods should be fine, because they’ll be unaffected by time-zones. I’d just assumed that the minutes would also be unaffected, but obviously forgot that some places have half-hour differences.