java - Creating a DateTime from two other dates -
basically want see if someones birthday within 3 months of todays date. going use days , "90" days.
thoughts follows:
- i set new datetime todays date , grab dob of person in question.
- i want take day , month dob , year todays date.
- then these days, months , years merged 1 new date.
for example:
dob 04/05/1987
today 10/05/2013
newbirth 04/05/2013
how can achieve part grab days/months 1 date, years another, , put these 1 date?
(only key factors, im aware rule wouldn't run)
import org.joda.time.readableinstant; import org.joda.time.datetime; import org.joda.time.days; import org.joda.time.months; import org.joda.time.years; rule"blah" salience 1 when proposer($dob : dateofbirth) datetime newbirth = new datetime() datetime today = new datetime(); #grab dob day , month #grab todays year #turn "newbirth" combination of above 2 lines int $birthday = (days.daysbetween((readableinstant)today,(readableinstant)newbirth).getdays()); if ($birthday <= 90){ logger.info("hurrraaayyyyyy"); } end
i standard jdk calendar
boolean iswithin3month(int y, int m, int d) { calendar = calendar.getinstance(); calendar birthday = new gregoriancalendar(y, m, d); int currentmonth = now.get(calendar.month); int birthdaymonth = birthday.get(calendar.month); int monthdiff; if (birthdaymonth < currentmonth) { // eg birth = jan (0) , curr = dec (11) monthdiff = 12 - currentmonth + birthdaymonth; } else { monthdiff = birthdaymonth - currentmonth; } if (monthdiff < 0 || monthdiff > 3) { return false; } else if (monthdiff == 0) { return birthday.get(calendar.date) >= now.get(calendar.date); } return true; }
Comments
Post a Comment