use of java.util.Calendar in project elasticsearch by elastic.
the class BaseXContentTestCase method testObject.
public void testObject() throws Exception {
Map<String, Object> object = new HashMap<>();
object.put("{'object':false}", Boolean.FALSE);
object.put("{'object':13}", (byte) 13);
object.put("{'object':5.0}", 5.0d);
object.put("{'object':8.0}", 8.0f);
object.put("{'object':{'lat':45.759429931640625,'lon':4.8394775390625}}", GeoPoint.fromGeohash("u05kq4k"));
object.put("{'object':3}", 3);
object.put("{'object':2}", 2L);
object.put("{'object':1}", (short) 1);
object.put("{'object':'string'}", "string");
object.put("{'object':'a'}", new Text("a"));
object.put("{'object':'b'}", new Text(new BytesArray("b")));
object.put("{'object':null}", null);
object.put("{'object':'OPEN'}", IndexMetaData.State.OPEN);
object.put("{'object':'NM'}", DistanceUnit.NAUTICALMILES);
object.put("{'object':{'f1':'v1'}}", singletonMap("f1", "v1"));
object.put("{'object':{'f1':{'f2':'v2'}}}", singletonMap("f1", singletonMap("f2", "v2")));
object.put("{'object':[1,2,3]}", Arrays.asList(1, 2, 3));
final String path = Constants.WINDOWS ? "{'object':'a\\\\b\\\\c'}" : "{'object':'a/b/c'}";
object.put(path, PathUtils.get("a", "b", "c"));
final DateTimeFormatter formatter = XContentBuilder.DEFAULT_DATE_PRINTER;
final Date d1 = new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC).toDate();
object.put("{'object':'" + formatter.print(d1.getTime()) + "'}", d1);
final DateTime d2 = DateTime.now();
object.put("{'object':'" + formatter.print(d2) + "'}", d2);
final Calendar c1 = new DateTime(2010, 1, 1, 0, 0, DateTimeZone.UTC).toCalendar(Locale.ROOT);
object.put("{'object':'2010-01-01T00:00:00.000Z'}", c1);
final ToXContent x1 = (builder, params) -> builder.startObject().field("f1", "v1").field("f2", 2).array("f3", 3, 4, 5).endObject();
final ToXContent x2 = (builder, params) -> builder.startObject().field("f1", "v1").field("f2", x1).endObject();
object.put("{'object':{'f1':'v1','f2':{'f1':'v1','f2':2,'f3':[3,4,5]}}}", x2);
for (Map.Entry<String, Object> o : object.entrySet()) {
final String expected = o.getKey();
assertResult(expected, () -> builder().humanReadable(true).startObject().field("object", o.getValue()).endObject());
assertResult(expected, () -> builder().humanReadable(true).startObject().field("object").value(o.getValue()).endObject());
}
assertResult("{'objects':[null,null,null]}", () -> builder().startObject().array("objects", null, null, null).endObject());
}
use of java.util.Calendar in project hibernate-orm by hibernate.
the class JdbcTimestampCustomSessionLevelTimeZoneTest method testTimeZone.
@Test
public void testTimeZone() {
connectionProvider.clear();
doInHibernateSessionBuilder(() -> {
return sessionFactory().withOptions().jdbcTimeZone(TIME_ZONE);
}, 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)).setTimestamp(anyInt(), any(Timestamp.class), calendarArgumentCaptor.capture());
assertEquals(TIME_ZONE, calendarArgumentCaptor.getValue().getTimeZone());
} catch (SQLException e) {
fail(e.getMessage());
}
connectionProvider.clear();
doInHibernateSessionBuilder(() -> {
return sessionFactory().withOptions().jdbcTimeZone(TIME_ZONE);
}, s -> {
s.doWork(connection -> {
try (Statement st = connection.createStatement()) {
try (ResultSet rs = st.executeQuery("select createdOn from Person")) {
while (rs.next()) {
Timestamp timestamp = rs.getTimestamp(1);
int offsetDiff = TimeZone.getDefault().getOffset(0) - TIME_ZONE.getOffset(0);
assertEquals(Math.abs(Long.valueOf(offsetDiff).longValue()), Math.abs(timestamp.getTime()));
}
}
}
});
Person person = s.find(Person.class, 1L);
assertEquals(0, person.createdOn.getTime());
});
}
use of java.util.Calendar in project head by mifos.
the class RepaymentScheduleInstallment method getDueDateValueAsCalendar.
public Calendar getDueDateValueAsCalendar() {
if (dueDateValue == null) {
return null;
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(dueDateValue);
return calendar;
}
use of java.util.Calendar in project head by mifos.
the class PictureFormFile method editFamilyInfo.
@TransactionDemarcate(joinToken = true)
public ActionForward editFamilyInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
ClientCustActionForm actionForm = (ClientCustActionForm) form;
actionForm.clearMostButNotAllFieldsOnActionForm();
ClientBO clientFromSession = getClientFromSession(request);
ClientFamilyInfoDto clientFamilyInfo = this.clientServiceFacade.retrieveFamilyInfoForEdit(clientFromSession.getGlobalCustNum());
SessionUtils.setCollectionAttribute(ClientConstants.LIVING_STATUS_ENTITY, clientFamilyInfo.getClientDropdowns().getLivingStatus(), request);
SessionUtils.setCollectionAttribute(ClientConstants.GENDER_ENTITY, clientFamilyInfo.getClientDropdowns().getGenders(), request);
SessionUtils.setCollectionAttribute(CustomerConstants.CUSTOM_FIELDS_LIST, new ArrayList<CustomFieldDto>(), request);
UserContext userContext = getUserContext(request);
List<SpouseFatherLookupEntity> spouseFather = legacyMasterDao.findMasterDataEntitiesWithLocale(SpouseFatherLookupEntity.class);
SessionUtils.setCollectionAttribute(ClientConstants.SPOUSE_FATHER_ENTITY, spouseFather, request);
SessionUtils.setAttribute(ClientConstants.ARE_FAMILY_DETAILS_MANDATORY, isFamilyDetailsMandatory(), request);
// customer specific
actionForm.setCustomerId(clientFamilyInfo.getCustomerDetail().getCustomerId().toString());
actionForm.setLoanOfficerId(clientFamilyInfo.getCustomerDetail().getLoanOfficerIdAsString());
actionForm.setGlobalCustNum(clientFamilyInfo.getCustomerDetail().getGlobalCustNum());
actionForm.setExternalId(clientFamilyInfo.getCustomerDetail().getExternalId());
// client specific
actionForm.setGovernmentId(clientFamilyInfo.getClientDetail().getGovernmentId());
actionForm.setDateOfBirth(clientFamilyInfo.getClientDetail().getDateOfBirth());
actionForm.initializeFamilyMember();
actionForm.setClientDetailView(clientFamilyInfo.getClientDetail().getCustomerDetail());
actionForm.setClientName(clientFamilyInfo.getClientDetail().getClientName());
actionForm.setSpouseName(clientFamilyInfo.getClientDetail().getSpouseName());
actionForm.setCustomFields(new ArrayList<CustomFieldDto>());
// client family specific
int familyMemberCount = 0;
for (ClientNameDetailDto familyMember : clientFamilyInfo.getFamilyMembers()) {
actionForm.addFamilyMember();
actionForm.setFamilyPrimaryKey(familyMemberCount, familyMember.getCustomerNameId());
actionForm.setFamilyFirstName(familyMemberCount, familyMember.getFirstName());
actionForm.setFamilyMiddleName(familyMemberCount, familyMember.getMiddleName());
actionForm.setFamilyLastName(familyMemberCount, familyMember.getLastName());
actionForm.setFamilySecondLastName(familyMemberCount, familyMember.getSecondLastName());
actionForm.setFamilyRelationship(familyMemberCount, familyMember.getNameType());
Map<Integer, List<ClientFamilyDetailDto>> clientFamilyDetailsMap = clientFamilyInfo.getClientFamilyDetails();
Integer key = Integer.valueOf(familyMemberCount);
List<ClientFamilyDetailDto> clientFamilyDetails = clientFamilyDetailsMap.get(key);
if (clientFamilyDetails != null) {
for (ClientFamilyDetailDto clientFamilyDetailDto : clientFamilyDetails) {
Calendar cal = Calendar.getInstance();
if (clientFamilyDetailDto.getDateOfBirth() != null) {
String date1 = DateUtils.makeDateAsSentFromBrowser(clientFamilyDetailDto.getDateOfBirth());
java.util.Date date = DateUtils.getDate(date1);
cal.setTime(date);
actionForm.setFamilyDateOfBirthDD(familyMemberCount, String.valueOf(cal.get(Calendar.DAY_OF_MONTH)));
actionForm.setFamilyDateOfBirthMM(familyMemberCount, String.valueOf(cal.get(Calendar.MONTH) + 1));
actionForm.setFamilyDateOfBirthYY(familyMemberCount, String.valueOf(cal.get(Calendar.YEAR)));
}
actionForm.setFamilyGender(familyMemberCount, clientFamilyDetailDto.getGender());
actionForm.setFamilyLivingStatus(familyMemberCount, clientFamilyDetailDto.getLivingStatus());
}
}
familyMemberCount++;
}
ClientBO client = this.customerDao.findClientBySystemId(clientFromSession.getGlobalCustNum());
actionForm.setAddress(Address.toAddress(client.getAddress()));
SessionUtils.removeThenSetAttribute(Constants.BUSINESS_KEY, client, request);
return mapping.findForward(ActionForwards.editFamilyInfo_success.toString());
}
use of java.util.Calendar in project head by mifos.
the class BulkEntryActionForm method setTransactionDate.
public void setTransactionDate(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);
setTransactionDateDD(Integer.toString(day));
setTransactionDateMM(Integer.toString(month));
setTransactionDateYY(Integer.toString(year));
}
Aggregations