Search in sources :

Example 26 with Calendar

use of java.util.Calendar in project head by mifos.

the class BulkEntryActionForm method setReceiptDate.

public void setReceiptDate(java.util.Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    // note that Calendar retrieves 0-based month, so increment month field
    int day = c.get(Calendar.DAY_OF_MONTH);
    int month = c.get(Calendar.MONTH) + 1;
    int year = c.get(Calendar.YEAR);
    setReceiptDateDD(Integer.toString(day));
    setReceiptDateMM(Integer.toString(month));
    setReceiptDateYY(Integer.toString(year));
}
Also used : Calendar(java.util.Calendar)

Example 27 with Calendar

use of java.util.Calendar in project head by mifos.

the class LoanAccountActionStrutsTest method offSetCurrentDate.

private String offSetCurrentDate(int noOfDays, Locale locale) throws InvalidDateException {
    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);
    java.sql.Date currentDate = new java.sql.Date(currentDateCalendar.getTimeInMillis());
    SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, locale);
    String userfmt = DateUtils.convertToCurrentDateFormat(format.toPattern());
    return DateUtils.convertDbToUserFmt(currentDate.toString(), userfmt);
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 28 with Calendar

use of java.util.Calendar in project head by mifos.

the class BulkEntryActionStrutsTest method testSuccessfulCreate.

@Test
public void testSuccessfulCreate() throws Exception {
    CollectionSheetEntryGridDto bulkEntry = getSuccessfulBulkEntry();
    Calendar meetingDateCalendar = new GregorianCalendar();
    int year = meetingDateCalendar.get(Calendar.YEAR);
    int month = meetingDateCalendar.get(Calendar.MONTH);
    int day = meetingDateCalendar.get(Calendar.DAY_OF_MONTH);
    meetingDateCalendar = new GregorianCalendar(year, month, day);
    Date meetingDate = new Date(meetingDateCalendar.getTimeInMillis());
    HashMap<Integer, ClientAttendanceDto> clientAttendance = new HashMap<Integer, ClientAttendanceDto>();
    clientAttendance.put(1, getClientAttendanceDto(1, meetingDate));
    clientAttendance.put(2, getClientAttendanceDto(2, meetingDate));
    clientAttendance.put(3, getClientAttendanceDto(3, meetingDate));
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    addRequestParameter("attendanceSelected[0]", "2");
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    SessionUtils.setAttribute(CollectionSheetEntryConstants.BULKENTRY, bulkEntry, request);
    setRequestPathInfo("/collectionsheetaction.do");
    addRequestParameter("method", "preview");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    addRequestDateParameter("transactionDate", day + "/" + (month + 1) + "/" + year);
    if (SUPPLY_ENTERED_AMOUNT_PARAMETERS) {
        addParametersForEnteredAmount();
        addParametersForDisbursalEnteredAmount();
    }
    performNoErrors();
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    setRequestPathInfo("/collectionsheetaction.do");
    addRequestParameter("method", "create");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    addRequestParameter("attendanceSelected[0]", "2");
    addRequestDateParameter("transactionDate", day + "/" + (month + 1) + "/" + year);
    addRequestParameter("customerId", "1");
    performNoErrors();
    verifyForward("create_success");
    Assert.assertNotNull(request.getAttribute(CollectionSheetEntryConstants.CENTER));
    Assert.assertEquals(request.getAttribute(CollectionSheetEntryConstants.CENTER), center.getDisplayName());
    StaticHibernateUtil.flushAndClearSession();
    groupAccount = TestObjectFactory.getObject(LoanBO.class, groupAccount.getAccountId());
    clientAccount = TestObjectFactory.getObject(LoanBO.class, clientAccount.getAccountId());
    centerSavingsAccount = TestObjectFactory.getObject(SavingsBO.class, centerSavingsAccount.getAccountId());
    clientSavingsAccount = TestObjectFactory.getObject(SavingsBO.class, clientSavingsAccount.getAccountId());
    groupSavingsAccount = TestObjectFactory.getObject(SavingsBO.class, groupSavingsAccount.getAccountId());
    center = TestObjectFactory.getCustomer(center.getCustomerId());
    group = TestObjectFactory.getCustomer(group.getCustomerId());
    client = TestObjectFactory.getClient(client.getCustomerId());
    Assert.assertEquals(1, client.getClientAttendances().size());
    Assert.assertEquals(AttendanceType.ABSENT, client.getClientAttendanceForMeeting(new java.sql.Date(meetingDateCalendar.getTimeInMillis())).getAttendanceAsEnum());
}
Also used : HashMap(java.util.HashMap) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) LoanBO(org.mifos.accounts.loan.business.LoanBO) GregorianCalendar(java.util.GregorianCalendar) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) Date(java.util.Date) ClientAttendanceDto(org.mifos.customers.client.business.service.ClientAttendanceDto) CollectionSheetEntryGridDto(org.mifos.application.collectionsheet.business.CollectionSheetEntryGridDto) Test(org.junit.Test)

Example 29 with Calendar

use of java.util.Calendar in project head by mifos.

the class SavingsTestHelper method getDate.

public Date getDate(String date, int hr, int min) throws ParseException {
    Calendar cal = Calendar.getInstance(Configuration.getInstance().getSystemConfig().getMifosTimeZone());
    cal.setTime(getDate(date));
    cal.set(Calendar.HOUR, hr);
    cal.set(Calendar.MINUTE, min);
    return cal.getTime();
}
Also used : Calendar(java.util.Calendar)

Example 30 with Calendar

use of java.util.Calendar in project hibernate-orm by hibernate.

the class JdbcTimeCustomTimeZoneTest method testTimeZone.

@Test
public void testTimeZone() {
    connectionProvider.clear();
    doInHibernate(this::sessionFactory, s -> {
        Person person = new Person();
        person.id = 1L;
        s.persist(person);
    });
    assertEquals(1, connectionProvider.getPreparedStatements().size());
    PreparedStatement ps = connectionProvider.getPreparedStatements().get(0);
    try {
        ArgumentCaptor<Calendar> calendarArgumentCaptor = ArgumentCaptor.forClass(Calendar.class);
        verify(ps, times(1)).setTime(anyInt(), any(Time.class), calendarArgumentCaptor.capture());
        assertEquals(TIME_ZONE, calendarArgumentCaptor.getValue().getTimeZone());
    } catch (SQLException e) {
        fail(e.getMessage());
    }
    connectionProvider.clear();
    doInHibernate(this::sessionFactory, s -> {
        s.doWork(connection -> {
            try (Statement st = connection.createStatement()) {
                try (ResultSet rs = st.executeQuery("select createdOn from Person")) {
                    while (rs.next()) {
                        Time time = rs.getTime(1);
                        Time offsetTime = Time.valueOf(OffsetTime.ofInstant(Instant.ofEpochMilli(0), TIME_ZONE.toZoneId()).toLocalTime());
                        assertEquals(offsetTime, time);
                    }
                }
            }
        });
        Person person = s.find(Person.class, 1L);
        assertEquals(0, person.createdOn.getTime() % TimeUnit.DAYS.toSeconds(1));
    });
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Calendar(java.util.Calendar) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Time(java.sql.Time) OffsetTime(java.time.OffsetTime) Test(org.junit.Test)

Aggregations

Calendar (java.util.Calendar)9441 Date (java.util.Date)2433 GregorianCalendar (java.util.GregorianCalendar)2129 Test (org.junit.Test)1734 SimpleDateFormat (java.text.SimpleDateFormat)889 ArrayList (java.util.ArrayList)476 ParseException (java.text.ParseException)352 HashMap (java.util.HashMap)270 TimeZone (java.util.TimeZone)270 IOException (java.io.IOException)235 DateFormat (java.text.DateFormat)224 Timestamp (java.sql.Timestamp)192 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