Search in sources :

Example 71 with Calendar

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);
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar)

Example 72 with Calendar

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;
}
Also used : DateMidnight(org.joda.time.DateMidnight) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar)

Example 73 with Calendar

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));
}
Also used : Locale(java.util.Locale) LocalizationConverter(org.mifos.framework.util.LocalizationConverter) SimpleTimeZone(java.util.SimpleTimeZone) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 74 with 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()));
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Date(java.sql.Date)

Example 75 with Calendar

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());
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Date(java.sql.Date)

Aggregations

Calendar (java.util.Calendar)9446 Date (java.util.Date)2436 GregorianCalendar (java.util.GregorianCalendar)2130 Test (org.junit.Test)1735 SimpleDateFormat (java.text.SimpleDateFormat)889 ArrayList (java.util.ArrayList)476 ParseException (java.text.ParseException)353 HashMap (java.util.HashMap)270 TimeZone (java.util.TimeZone)270 IOException (java.io.IOException)235 DateFormat (java.text.DateFormat)224 Timestamp (java.sql.Timestamp)194 List (java.util.List)187 File (java.io.File)167 Map (java.util.Map)149 BigDecimal (java.math.BigDecimal)134 Locale (java.util.Locale)134 Test (org.testng.annotations.Test)118 Identity (org.olat.core.id.Identity)112 Date (java.sql.Date)110