Time::getCurrentTime() returning current system time?


#1

Hello All,
I’ve a very basic scenario in which I need the exact system time… Also juce::Time is giving me the proper output throughout the life of the app… But I’ve observed the case that if I update my system time manually and then check my Time::getCurrentTime() then I am still getting the previous time value… Can someone help me to get the updated value… Thanks so much…


#2

FWIW, I believe that the issue is the implementation of getCurrentTime().

It appears that getCurrentTime calls currentTimeMillis(). That call only gets the system time initially, or when the static counter wraps.


#3

Yup you are right, thanks for your views… I think that’s the scenario… Its not updated once my system is up and running… Do you find any solution for this…?


#4

As a workaround, I made my own getSystemTime() call. It is essentially the guts of the millis call used in the Time class, without the ‘- now’ conversion to an ‘offset’.

I then pass in that result, which is an int64 of mS since the epoch, to one of the Time constructors, so I can use all the normal time methods.

But I reported the issue to Jules, since there are other ramifications (ex. when the computer goes to sleep, the mS timer can stop), so I’m sure he’ll update the Time class eventually.


#5

Thanks guys, I know about this - will get it sorted within the next couple of days…


#6

Thanks so much jfitzpat & jules… I really appreciate the help…


#7

The thing is that Time and Clock are totally different concept, and often overlooked by library programmer.
A clock is something that increase linearly, whatever the state of the computer, the face of the moon etc… It doesn’t jump back (never ever). And whatever the state when you call it, it’s guarranted that int a = getClock(), b = getClock() => b > a. (think of a multithreaded program running on different core)

A time is something that can jiggle, go back, be offset anytime. It’s sometime, we, human make sense of it.

When you need a time to measure something, you actually need a clock (typically using clock_gettime(CLOCK_MONOTONIC) under linux).
When you need to display/parse something coming from the user, you need a time (typically using clock_gettime(CLOCK_REALTIME) under linux).

Currently, Juce implementation of Time is mixing the concepts too.