List of usage examples for org.apache.commons.lang3.time DateUtils parseDate
public static Date parseDate(final String str, final String... parsePatterns) throws ParseException
Parses a string representing a date by trying a variety of different parsers.
The parse will try each parse pattern in turn.
From source file:org.glenans.extractor.model.Stage.java
public static Date convertStringToDate(String stringDate) { /*/*from w w w. j a va 2 s. com*/ Date can have two formats: - "04/10/15" for october, 4th 2015 - "04/10/15 14h00" for october, 4th 2015, 2pm */ DateFormat df = new SimpleDateFormat("dd/MM/yy", Locale.FRANCE); DateFormat dfWithTime = new SimpleDateFormat("d/MM/yy '' HH'h'mm", Locale.FRANCE); try { LOGGER.info("Date : " + stringDate); return DateUtils.parseDate(stringDate, ALL_DATE_PARSERS); } catch (ParseException ex) { LOGGER.info("ParseException : " + ex); } return null; }
From source file:org.hscieripple.common.util.HSCIEDateFormatter.java
public static Date toDate(String input, String systemFrom) { //Define incoming date format by system if (input == null) { return null; }/* w w w.jav a 2 s .co m*/ String format = "dd.MM.yyyy"; switch (systemFrom) { case "Liquid Logic": case "PCS": case "Emis Community": format = "yyyy-MM-dd HH:mm:ss"; break; case "PCS Time": case "PCS long Time": format = "yyyy-MM-dd HH:mm:ss"; break; case "PCS alerts": format = "yyyy-MM-dd HH:mm"; break; case "RIO": if (input.contains("-")) { format = "yyyy-MM-dd HH:mm:ss"; } else { format = "dd/MM/yyyy HH:mm"; } break; } //Return value of formatted String try { return DateUtils.parseDate(input, format); } catch (ParseException ignore) { return null; } }
From source file:org.jamwiki.migrate.MediaWikiXmlImporter.java
/** * *//*from w w w . j av a 2s . co m*/ private Timestamp parseMediaWikiTimestamp(String timestamp) { try { Date date = DateUtils.parseDate(timestamp, new String[] { MediaWikiConstants.ISO_8601_DATE_FORMAT }); return new Timestamp(date.getTime()); } catch (ParseException e) { // FIXME - this should be handled somehow return new Timestamp(System.currentTimeMillis()); } }
From source file:org.karndo.piracy.Scraper.java
/** * /*from ww w. j av a 2s .com*/ * @param url * @param io * @return */ public LinkedList<PiracyEvent> parse_piracy_data(String url, InputOutput io) throws IOException { //use the private method in this class to get the data String data = get_piracy_data(url); System.out.println(data); //strip everything before "icons" String temp = StringUtils.strip(data, "head.ready(function() {fabrikMap45 = new FbGoogleMapViz('table_map', {\"icons\":["); temp = "\"" + temp; //after stripping the first section, the data can be split using the //'curly brackets' String[] events = StringUtils.split(temp, "{"); LinkedList<PiracyEvent> events_list = new LinkedList<PiracyEvent>(); //some parameters for holding data from the event strings PiracyEvent event1 = null; double longitude = 0.0; double latitude = 0.0; String attack_id = ""; String vessel_type = ""; String status = ""; Date date = null; for (String str : events) { try { //Strip out the latitude and longitude String lat1 = StringUtils.strip(StringUtils.substringBetween(str, "\"0\":", ","), "\""); String long1 = StringUtils.strip(StringUtils.substringBetween(str, "\"1\":", ","), "\""); //parse the values into doubles latitude = Double.parseDouble(lat1); longitude = Double.parseDouble(long1); //strip out the attack id. attack_id = StringUtils.strip(StringUtils.substringBetween(str, "\"2\":", "<br \\/>"), "\"Attack ID:"); //strip out the date String date_str = StringUtils.strip(StringUtils.substringBetween(str, "Date:", "<br"), "Date:"); // TODO change this to a GMT time-format date = DateUtils.parseDate(StringUtils.trim(date_str), "yyyy-MM-dd"); //strip out the Vessel type vessel_type = StringUtils.strip(StringUtils.substringBetween(str, "Vessel:", "<br \\/>"), "Vessel:"); //strip out the status status = StringUtils.strip(StringUtils.substringBetween(str, "Status:", "<br \\/>"), "Status:"); //create a piracy event event1 = new PiracyEvent(latitude, longitude, attack_id, date, StringUtils.trim(status), StringUtils.trim(vessel_type)); events_list.add(event1); //print to the supplied InputOutput from the main window io.getOut().println(event1); } catch (ParseException ex) { System.err.println("A parse exception occurred parsing the date"); System.err.println(ex.getMessage()); } finally { } } return events_list; }
From source file:org.kuali.coeus.common.framework.person.KcPerson.java
/** * Gets the value of age. Will return null if not set. * * @return the value of age/*www . j a v a 2 s . com*/ */ @Override public Integer getAge() { final EntityBioDemographicsContract bio = this.entity.getBioDemographics(); if (bio == null) { return null; } Date birthDate = null; try { birthDate = (bio.getBirthDate() != null) ? DateUtils.parseDate(bio.getBirthDate(), new String[] { "mm/dd/yyyy" }) : null; } catch (ParseException e) { LOG.warn(e.getMessage(), e); } return birthDate != null ? this.calcAge(birthDate) : null; }
From source file:org.lazulite.boot.autoconfigure.core.xml.converter.SingleValueDateConverter.java
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Date date = null;//from w w w. j a v a2s . c o m try { date = DateUtils.parseDate(reader.getValue(), pattern); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return date; }
From source file:org.openhab.binding.IEEE1888.server.FIAPServer.java
private Point buidPoint(URI id, String valueStr) throws ParseException { // analyze value HashMap<String, String> keyValueMap = new HashMap<>(); if (valueStr != null) { String[] values = StringUtils.split(valueStr, "&"); if (values != null) { for (String value : values) { keyValueMap.put(StringUtils.substringBefore(value, "="), StringUtils.substringAfter(value, "=")); }//from w w w . j a v a 2 s . co m } } // [point] Point point = new Point(); point.setId(id); Value value = new Value(); // [time] Calendar timeValue = Calendar.getInstance(); if (StringUtils.isNotBlank(keyValueMap.get("time"))) { Date dateTime = DateUtils.parseDate(keyValueMap.get("time"), TIME_FORMAT); timeValue.setTime(dateTime); } value.setTime(timeValue); // [value] String v; if (keyValueMap.containsKey("value")) { v = keyValueMap.get("value"); } else { v = valueStr; } if (v == null) { v = ""; } value.setString(v); point.addValue(value); return point; }
From source file:org.openhab.binding.IEEE1888.trap.TrapManager.java
/** * If there are any updates, data were sened. * * @param itemName//from w w w . jav a2 s . c om * @param newState */ public static void putTrapData(String itemName, State newState) throws ParseException { if (!trapMap.containsKey(itemName)) { // If there is not trap, trap is never processed. return; } TrapInfo trapInfo = trapMap.get(itemName); Value pointValue = trapInfo.getPoint().getValue()[0]; String newValue = newState.toString(); Pattern STATE_CONFIG_PATTERN = Pattern.compile("(.*?)\\=(.*?)\\&(.*?)\\=(.*?)"); // analyze state Matcher matcher = STATE_CONFIG_PATTERN.matcher(newValue); if (matcher.find()) { String[] values = StringUtils.split(newValue, "&"); HashMap<String, String> keyValueMap = new HashMap<>(); for (String value : values) { keyValueMap.put(StringUtils.substringBefore(value, "="), StringUtils.substringAfter(value, "=")); } Calendar timeValue = Calendar.getInstance(); if (StringUtils.isNotBlank(keyValueMap.get("time"))) { Date dateTime = DateUtils.parseDate(keyValueMap.get("time"), TIME_FORMAT); timeValue.setTime(dateTime); } if ((timeValue.compareTo(pointValue.getTime()) == 0) && StringUtils.equals(keyValueMap.get("value"), pointValue.getString())) { // If state was not changed, trap is not processed. return; } pointValue.setString(keyValueMap.get("value")); pointValue.setTime(timeValue); } else { if (StringUtils.equals(newValue, pointValue.getString())) { // If state was not changed, trap is not processed. return; } pointValue.setString(newValue); pointValue.setTime(Calendar.getInstance()); } // send data Map<String, Date> CallbackURLMap = trapInfo.getCallbackURLMap(); CallbackURLMap.keySet().forEach(key -> new Thread(() -> { sendData(key, trapInfo); }).start()); }
From source file:org.openlmis.rnr.service.CalculationServiceTest.java
@Test public void shouldUseCurrentPeriodStartDateToCalculateDForEmergencyRnr() throws Exception { rnr.setEmergency(true);//from w w w . j av a 2 s .c o m rnr.setCreatedDate(DateUtils.parseDate("01-02-12", "dd-MM-yy")); RnrLineItem lineItem = rnr.getFullSupplyLineItems().get(0); ProcessingPeriod previousPeriod = new ProcessingPeriod(2l, new Date(), new Date(), 3, "previousPeriod"); when(processingScheduleService.getNPreviousPeriodsInDescOrder(rnr.getPeriod(), 2)) .thenReturn(asList(previousPeriod)); calculationService.fillReportingDays(rnr); Integer expectedNumberOfDays = 31; assertThat(lineItem.getReportingDays(), is(expectedNumberOfDays)); verify(processingScheduleService).getNPreviousPeriodsInDescOrder(rnr.getPeriod(), 2); verify(requisitionRepository, never()).getAuthorizedDateForPreviousLineItem(rnr, lineItem.getProductCode(), previousPeriod.getStartDate()); }
From source file:org.openmrs.api.CohortServiceTest.java
@Test public void getCohortMemberships_shouldNotGetMembershipsContainingPatientOutsideDateRange() throws Exception { executeDataSet(COHORT_XML);/*from www .j av a2 s . c o m*/ Date longAgo = DateUtils.parseDate("1999-12-31", "yyyy-MM-dd"); List<CohortMembership> memberships = service.getCohortMemberships(6, longAgo, false); assertThat(memberships.size(), is(0)); }