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));
}
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);
}
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());
}
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();
}
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));
});
}
Aggregations