JavaMe Library you might need: Part 2

Following my previous post, I have a new addition to the library. This time its a Date utility. Here is the code

package com.trinisoft.mlib.util;

/**
*
* @author trinisoftinc
*/

public class Date extends java.util.Date {
public boolean isAfter(java.util.Date date) {
if(this.getTime() > date.getTime()) {
return true;
}
return false;
}

public boolean isBefore(java.util.Date date) {
if(this.getTime() < date.getTime()) {
return true;
}
return false;
}

public Date afterSeconds(int secs) {
Date newDate = this;
newDate.setTime(this.getTime() + (secs * 1000));
return newDate;
}

public Date afterMinutes(int mins) {
Date newDate = this;
newDate.setTime(this.getTime() + (mins * 60 * 1000));
return newDate;
}

public Date afterHours(int hours) {
Date newDate = this;
newDate.setTime(this.getTime() + (hours * 60 * 60 * 1000));
return newDate;
}

public Date afterDays(int days) {
Date newDate = this;
newDate.setTime(this.getTime() + (days * 24 * 60 * 60 * 1000));
return newDate;
}

public Date afterWeeks(int weeks) {
Date newDate = this;
newDate.setTime(this.getTime() + (weeks * 7 * 24 * 60 * 60 * 1000));
return newDate;
}
}

Now in your code, say you have a date object, you can do this

dateObject.isBefore(anotherDate);
Date newDate = dateObject.afterHours(24);
........

You can try it out. I also will appreciate suggestions.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: