List of usage examples for java.text DateFormat parse
public Date parse(String source) throws ParseException
From source file:com.amazon.notification.utils.DataManager.java
public int compareDates(String dateString1, String dateString2) { Date date1 = null, date2 = null; try {// www.j a v a 2 s . c o m DateFormat format = new SimpleDateFormat("dd-M-yyyy", Locale.ENGLISH); date1 = format.parse(dateString1); date2 = format.parse(dateString2); } catch (Exception e) { } return date1.compareTo(date2); }
From source file:com.gisgraphy.util.TimestampConverter.java
/** * Convert a String to a date//from w ww . j a va 2 s .c o m * * @param type * java.util.Date * @param value * the String value * @return a converted date */ @SuppressWarnings("unchecked") protected Object convertToDate(Class type, Object value) { DateFormat df = new SimpleDateFormat(TS_FORMAT); if (value instanceof String) { try { if (StringUtils.isEmpty(value.toString())) { return null; } return df.parse((String) value); } catch (Exception pe) { throw new ConversionException("Error converting String to Timestamp"); } } throw new ConversionException("Could not convert " + value.getClass().getName() + " to " + type.getName()); }
From source file:com.haulmont.chile.core.datatypes.impl.DateTimeDatatype.java
@Override public Date parse(String value) throws ParseException { if (StringUtils.isBlank(value)) { return null; }/*from www .j a v a 2s. c o m*/ DateFormat format; if (formatPattern != null) { format = new SimpleDateFormat(formatPattern); } else { format = DateFormat.getDateInstance(); } return format.parse(value.trim()); }
From source file:com.mobileman.projecth.business.patient.PatientMedicationServiceTest.java
/** * /*from w w w .ja va 2 s.c o m*/ * @throws Exception */ @Test public void addConsumedMedicationWeekly() throws Exception { int oldSize = patientMedicationDao.findAll().size(); Patient patient = (Patient) userService.findUserByLogin("sysuser1"); assertNotNull(patient); Medication medication = medicationService.findByName("Kort 2", Locale.GERMANY).get(0); Disease disease = diseaseService.findByCode(DiseaseCodes.RHEUMA_CODE); assertNotNull(disease); DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy"); Date startDate = dateFormat.parse("1.11.2010"); Date endDate = dateFormat.parse("28.11.2010"); patientMedicationService.addConsumedMedication(patient.getId(), disease.getId(), medication.getId(), 2.0d, MedicationFrequency.WEEKLY, startDate, endDate, null); assertEquals(oldSize + 4, patientMedicationDao.findAll().size()); }
From source file:com.mobileman.projecth.business.patient.PatientMedicationServiceTest.java
/** * /*www . j a v a 2 s . com*/ * @throws Exception */ @Test public void addConsumedMedicationBiWeekly() throws Exception { int oldSize = patientMedicationDao.findAll().size(); Patient patient = (Patient) userService.findUserByLogin("sysuser1"); assertNotNull(patient); Medication medication = medicationService.findByName("Kort 2", Locale.GERMANY).get(0); Disease disease = diseaseService.findByCode(DiseaseCodes.RHEUMA_CODE); assertNotNull(disease); DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy"); Date startDate = dateFormat.parse("1.11.2010"); Date endDate = dateFormat.parse("28.11.2010"); patientMedicationService.addConsumedMedication(patient.getId(), disease.getId(), medication.getId(), 2.0d, MedicationFrequency.BI_WEEKLY, startDate, endDate, null); assertEquals(oldSize + 2, patientMedicationDao.findAll().size()); }
From source file:com.mobileman.projecth.business.patient.PatientMedicationServiceTest.java
/** * {@link PatientMedicationService#findConsumedMedicationsDiary(Long, Long, java.util.Date, java.util.Date)} * @throws Exception//from w w w . j av a2 s.c om */ @Test public void findPatientConsumedMedicationsDiary() throws Exception { Patient patient = (Patient) userService.findUserByLogin("sysuser1"); assertNotNull(patient); Disease disease = diseaseService.findByCode("M79.0"); assertNotNull(disease); DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy"); Date startDate = dateFormat.parse("1.11.2010"); Date endDate = dateFormat.parse("3.11.2010"); List<Object[]> result = patientMedicationService.findConsumedMedicationsDiary(patient.getId(), disease.getId(), startDate, endDate); assertNotNull(result); assertEquals(5, result.size()); assertEquals(2, Number.class.cast(result.get(2)[2]).intValue()); assertEquals(2, Number.class.cast(result.get(3)[2]).intValue()); for (Object[] row : result) { assertTrue(Medication.class.isInstance(row[1])); } }
From source file:com.mobileman.projecth.business.patient.PatientMedicationServiceTest.java
/** * {@link PatientMedicationService#findConsumedMedicationsDiary(Long, java.util.Date, java.util.Date)} * @throws Exception//ww w . j a v a 2 s. c o m */ @Test public void findPatientConsumedMedicationsDiary2() throws Exception { Patient patient = (Patient) userService.findUserByLogin("sysuser1"); assertNotNull(patient); Disease disease = diseaseService.findByCode("M79.0"); assertNotNull(disease); DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy"); Date startDate = dateFormat.parse("1.11.2010"); Date endDate = dateFormat.parse("3.11.2010"); List<Object[]> result = patientMedicationService.findConsumedMedicationsDiary(patient.getId(), startDate, endDate); assertNotNull(result); assertEquals(5, result.size()); assertEquals(2, Number.class.cast(result.get(2)[2]).intValue()); assertEquals(2, Number.class.cast(result.get(3)[2]).intValue()); for (Object[] row : result) { assertTrue(Medication.class.isInstance(row[1])); } }
From source file:biblivre3.administration.ReportsHandler.java
private ReportsDTO populateDto(HttpServletRequest request, HashMap<String, String> model) throws Exception { ReportsDTO dto = new ReportsDTO(); String reportId = model.get("reportId"); ReportType type = ReportType.getById(reportId); dto.setType(type);//w ww.jav a 2s.com if (type.isTimePeriod()) { String defaultFormat = I18nUtils.getText(request.getSession(), "biblivre3", "DEFAULT_DATE_FORMAT"); DateFormat formatter = new SimpleDateFormat(defaultFormat); formatter.setLenient(false); String initialDate = model.get("initialDate"); Date parsedStartDate = (Date) formatter.parse(initialDate); dto.setInitialDate(parsedStartDate); String finalDate = model.get("finalDate"); Date parsedFinalDate = (Date) formatter.parse(finalDate); dto.setFinalDate(parsedFinalDate); } String database = model.get("database"); dto.setDatabase(Database.valueOf(database)); String order = model.get("order"); dto.setOrder(order); String userId = model.get("userId"); dto.setUserId(userId); String recordIds = model.get("recordIds"); dto.setRecordIds(recordIds); String authorName = model.get("authorName"); dto.setAuthorName(authorName); String datafield = model.get("datafield"); dto.setDatafield(datafield); String digits = model.get("digits"); try { dto.setDigits(Integer.valueOf(digits)); } catch (Exception pokemon) { } return dto; }
From source file:com.redhat.lightblue.metadata.types.DateType.java
@Override public Object cast(Object obj) { Date value = null;/*from w w w. j av a 2 s . c om*/ if (obj != null) { DateFormat fmt = getDateFormat(); if (obj instanceof Date) { value = (Date) obj; } else if (obj instanceof String) { try { value = fmt.parse((String) obj); } catch (ParseException e) { throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, obj.toString()); } } else { throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, obj.toString()); } } return value; }
From source file:fr.noop.subtitle.stl.StlParser.java
private Date readDate(String dateString) throws IOException { DateFormat df = new SimpleDateFormat("yyMMdd"); try {//from w ww . java2 s .c om return df.parse(dateString); } catch (ParseException e) { throw new IOException("Unable to parse date"); } }