use of java.util.Calendar in project head by mifos.
the class TestObjectFactory method getDayForDate.
/**
* Return the int corresponding to the day of the week of the date parameter. Returns Calendar.SUNDAY (1),
* Calendar.MONDAY (2), etc.
*/
public static int getDayForDate(final Date date) {
Calendar dateConversionCalendar = new GregorianCalendar();
dateConversionCalendar.setTime(date);
return dateConversionCalendar.get(Calendar.DAY_OF_WEEK);
}
use of java.util.Calendar in project head by mifos.
the class PersonnelInformationDto method dateDiffInYears.
private int dateDiffInYears(java.sql.Date fromDate) {
Calendar fromDateCal = new GregorianCalendar();
fromDateCal.setTime(fromDate);
// Create a calendar object with today's date
Calendar today = new DateMidnight().toGregorianCalendar();
// Get age based on year
int age = today.get(Calendar.YEAR) - fromDateCal.get(Calendar.YEAR);
int monthDiff = (today.get(Calendar.MONTH) + 1) - (fromDateCal.get(Calendar.MONTH) + 1);
int dayDiff = today.get(Calendar.DAY_OF_MONTH) - fromDateCal.get(Calendar.DAY_OF_MONTH);
// If this year's birthday has not happened yet, subtract one from age
if (monthDiff < 0) {
age--;
} else if (monthDiff == 0) {
if (dayDiff < 0) {
age--;
}
}
return age;
}
use of java.util.Calendar in project head by mifos.
the class FiscalCalendarRulesTest method testIsWorkingDay.
@Test
public void testIsWorkingDay() {
String configWorkingDays = "MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY";
setNewWorkingDays(configWorkingDays);
// get the supported ids for GMT-08:00 (Pacific Standard Time)
String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
// if no ids were returned, something is wrong. get out.
// Otherwise get an id for Pacific Standard Time
String pstId = ids[0];
// create a Pacific Standard Time time zone
SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, pstId);
// set up rules for daylight savings time
pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
// create a GregorianCalendar with the Pacific Daylight time zone
// and the current date and time
Calendar calendar = new GregorianCalendar(pdt);
try {
Locale savedLocale = Localization.getInstance().getConfiguredLocale();
new LocalizationConverter().setCurrentLocale(Locale.US);
SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, Locale.US);
// Keith: DateFormat must be set to the same timezone as the
// calendar
// Otherwise dates don't roll over at the same exact time, causing
// this and several other unit tests to fail
df.setTimeZone(TimeZone.getTimeZone(pstId));
df.applyPattern("yyyy/MM/dd");
Date thursday = df.parse("2007/10/11");
calendar.setTime(thursday);
String out = thursday.toString();
out.contains("A");
new LocalizationConverter().setCurrentLocale(savedLocale);
} catch (Exception e) {
}
Assert.assertTrue(new FiscalCalendarRules().isWorkingDay(calendar));
// Friday
calendar.add(Calendar.DAY_OF_WEEK, 1);
Assert.assertTrue(new FiscalCalendarRules().isWorkingDay(calendar));
// Sat
calendar.add(Calendar.DAY_OF_WEEK, 1);
Assert.assertTrue(!new FiscalCalendarRules().isWorkingDay(calendar));
// Sunday
calendar.add(Calendar.DAY_OF_WEEK, 1);
Assert.assertTrue(!new FiscalCalendarRules().isWorkingDay(calendar));
}
use of java.util.Calendar in project head by mifos.
the class CustomerAccountBOIntegrationTest method changeAllInstallmentDateToPreviousDate.
private void changeAllInstallmentDateToPreviousDate(final CustomerAccountBO customerAccountBO, final int noOfDays) {
Calendar currentDateCalendar = new GregorianCalendar();
int year = currentDateCalendar.get(Calendar.YEAR);
int month = currentDateCalendar.get(Calendar.MONTH);
int day = currentDateCalendar.get(Calendar.DAY_OF_MONTH);
currentDateCalendar = new GregorianCalendar(year, month, day - noOfDays);
for (AccountActionDateEntity accountActionDateEntity : customerAccountBO.getAccountActionDates()) {
((CustomerScheduleEntity) accountActionDateEntity).setActionDate(new java.sql.Date(currentDateCalendar.getTimeInMillis()));
}
}
use of java.util.Calendar in project head by mifos.
the class CustHistoricalDataActionStrutsTest method offSetCurrentDate.
private java.sql.Date offSetCurrentDate(int noOfDays) {
Calendar currentDateCalendar = new GregorianCalendar();
int year = currentDateCalendar.get(Calendar.YEAR);
int month = currentDateCalendar.get(Calendar.MONTH);
int day = currentDateCalendar.get(Calendar.DAY_OF_MONTH);
currentDateCalendar = new GregorianCalendar(year, month, day - noOfDays);
return new java.sql.Date(currentDateCalendar.getTimeInMillis());
}
Aggregations