Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 93
Registered: ‎08-18-2011
My Device: 9550
My Carrier: At&T

Time comparison in Cascade

Hi Guys,

 

could you suggest me what is the best approach for device time comparison?

 

I implemented as bellow  but sometime I am not getting correct output:

 

qint64 TimeOutThread::getSessionTimeOutTime(const int &mins){
	qint64 msec = (getSessionStartTime()+(qint64(mins*60 * 1000)));
	return msec;
}
qint64 TimeOutThread::getCurrentTime(){
	qint64 msec = QDateTime::currentMSecsSinceEpoch();
	return msec;
}
bool TimeOutThread::isSessionTimeOut(const int &mins){
	return (getCurrentTime() > getSessionTimeOutTime(mins));
}

 

Is this implementation correct?

 

 

Thanks,

Shwarup Biswas
Developer
Posts: 188
Registered: ‎07-19-2012
My Device: Z10 LE
My Carrier: Three

Re: Time comparison in Cascade

If you're just comparing two dates or times, you can use the standard comparison operators on QDateTime objects. I don't really see anything wrong with your implementation, but I find that using QDateTime objects allow for easier manipulation.



Did this post help you? If so, please make sure to "like" it!
Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Time comparison in Cascade

i would suggest that you debug your code and check if the numbers represent the timestamps you suspect. most likely some of the variables contains something different.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 93
Registered: ‎08-18-2011
My Device: 9550
My Carrier: At&T

Re: Time comparison in Cascade

Hi Guys,

 

Thanks for your help.

 

Hi Mdodd,

 

Could you tell me what is the API I can use for comparing two dates and times using "standard comparison operators". i refered "http://qt-project.org/doc/qt-4.8/qdatetime.html" document but not understand which api is correct for this comparison.

 

 

Thanks,

Shwarup Biswas
Developer
Posts: 206
Registered: ‎05-15-2012
My Device: None
My Carrier: Telus

Re: Time comparison in Cascade

I think he means create QDataTime instances and compare them with >,<, >=, <=, and ==.

----------------------
Check out my app, Alien Flow for reddit

And of course, like my post if you found it helpful or informative!