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

Java Development


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 63
Registered: ‎08-07-2009
My Device: Not Specified

Different OS - Different Calculation Results

hello, I spent a long time getting some code working correctly on my torch only to find that it produces different (incorrect) results on storm (os 5).

 

I am formating a date-time that the facebook api sends me to get the created time in a format such as 53 minutes ago, 1 hour ago, 2 hours ago, 1 day ago, etc.

 

I spent nearly a day on this so to the see the incorrect results with os 5 is just a kick in the teeth! Any help would be appreciated.

 

                String dateString = aPost.getCreated();

Date eventDate = new Date(HttpDateParser.parse(dateString));
Date currentDate = new Date();
long currentTime = currentDate.getTime();
long recordTime = eventDate.getTime();
if ( (recordTime <= currentTime + ((long) DateTimeUtilities.ONEDAY)) &&
     (recordTime >= currentTime - ((long) DateTimeUtilities.ONEDAY)) ) {
   long s  = currentTime - recordTime;
 int   hours = (int)(s / (1000*60*60));
int minutes = (int)(s % (1000*60*60)) / (1000*60);
Log.info("minutes is " + minutes);
Log.info("hours is " + hours);
if((hours == 0)&&((minutes == 0) || (minutes == 1)))
         {
    add(new LabelFieldCreated("1 minute ago"));
}
    else if(hours == 0)
         {
    add(new LabelFieldCreated(minutes + " minutes ago"));
}
   else if(hours == 1)
         {
    add(new LabelFieldCreated(hours + " hour ago"));
}
else
         {
    add(new LabelFieldCreated(hours + " hours ago"));
}
} else if ( (recordTime <= currentTime + ((long) DateTimeUtilities.ONEDAY * 2)) &&
     (recordTime >= currentTime - ((long) DateTimeUtilities.ONEDAY * 2)) ) {
    add(new LabelFieldCreated("1 day ago"));
}
else if ( (recordTime <= currentTime + ((long) DateTimeUtilities.ONEDAY * 3)) &&
     (recordTime >= currentTime - ((long) DateTimeUtilities.ONEDAY * 3)) ) {
    add(new LabelFieldCreated("2 days ago"));
}
else if ( (recordTime <= currentTime + ((long) DateTimeUtilities.ONEDAY * 4)) &&
     (recordTime >= currentTime - ((long) DateTimeUtilities.ONEDAY * 4)) ) {
    add(new LabelFieldCreated("3 days ago"));
}
else if ( (recordTime <= currentTime + ((long) DateTimeUtilities.ONEDAY * 5)) &&
     (recordTime >= currentTime - ((long) DateTimeUtilities.ONEDAY * 5)) ) {
    add(new LabelFieldCreated("4 days ago"));
}
else if ( (recordTime <= currentTime + ((long) DateTimeUtilities.ONEDAY * 6)) &&
     (recordTime >= currentTime - ((long) DateTimeUtilities.ONEDAY * 6)) ) {
    add(new LabelFieldCreated("5 days ago"));
}
else if ( (recordTime <= currentTime + ((long) DateTimeUtilities.ONEDAY * 7)) &&
     (recordTime >= currentTime - ((long) DateTimeUtilities.ONEDAY * 7)) ) {
    add(new LabelFieldCreated("6 days ago"));
}
else {
    add(new LabelFieldCreated("more than a week ago"));
}