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:jp.dip.komusubi.botter.gae.module.jal5971.FlightStatusEntry.java
public Date getScheduledArrivalDate() { try {/*from w ww. j a v a2 s .co m*/ return DateUtils.parseDate(getElement(column, 6).getText().trim(), new String[] { HOUR_FORMAT }); } catch (ParseException e) { logger.warn("scheduledArrivalDate() parse error {}", e.getLocalizedMessage()); return resolver.resolve(); } }
From source file:br.com.binarti.simplesearchexpr.SimpleSearchParserTest.java
@Test public void shouldParseSimpleSearchExpressionWithTwoFields() throws ParseException { SimpleSearchParser parser = new SimpleSearchParser( new SimpleSearchExpressionPlan(new SimpleSearchExpressionField("id", Integer.class), new SimpleSearchExpressionField("date", Date.class))); SimpleSearchExpression expr = parser.parse("id:1 date:10/06/2014"); assertEquals(2, expr.getOperations().size()); SimpleSearchRelationalOperation relationalOperation = expr.getOperations().get(0); assertEquals("id", relationalOperation.getField().getName()); assertEquals("id", relationalOperation.getField().getFieldExpr()); assertEquals(SimpleSearchRelationalOperator.EQUALS, relationalOperation.getOperator()); assertEquals(1, relationalOperation.getValue()); relationalOperation = expr.getOperations().get(1); assertEquals("date", relationalOperation.getField().getName()); assertEquals("date", relationalOperation.getField().getFieldExpr()); assertEquals(SimpleSearchRelationalOperator.EQUALS, relationalOperation.getOperator()); assertEquals(DateUtils.parseDate("10/06/2014", "dd/MM/yyyy"), relationalOperation.getValue()); }
From source file:jp.dip.komusubi.botter.gae.module.jal5971.FlightStatusEntry.java
public Date getDepartureDate() { Date date = null;//w ww . ja v a2 s . c o m try { if (getElement(column, 3) != null) date = DateUtils.parseDate(getElement(column, 3).getText().trim(), new String[] { HOUR_FORMAT }); } catch (ParseException e) { logger.warn("departureDate() parse error {}", e.getLocalizedMessage()); } return date; }
From source file:com.mmone.gpdati.allotment.record.AllotmentRecord.java
public Date getJDate() throws ParseException { return DateUtils.parseDate(dateFrom, "ddMMyyyy"); }
From source file:jp.dip.komusubi.botter.gae.module.jal5971.FlightStatusEntry.java
public Date getArrivalDate() { Date date = null;/*from w ww .j av a 2s. c o m*/ try { if (getElement(column, 7) != null) date = DateUtils.parseDate(getElement(column, 7).getText().trim(), new String[] { HOUR_FORMAT }); } catch (ParseException e) { logger.warn("arrivalDate() parse error {}", e.getLocalizedMessage()); } return date; }
From source file:net.orpiske.dcd.collector.dataset.impl.MBoxDataSet.java
private Date getDate(final String strDate) { final int DATE_LENGTH_WITH_TZ = 37; final int DATE_LENGTH_WITHOUT_TZ = 31; String dateWithCorrectSize;/*from w ww . j av a2s .c o m*/ if (strDate == null || strDate.isEmpty()) { logger.error("The input date is null, returning epoch"); return new Date(0); } int length = strDate.trim().length(); /* * DateUtils seems to fail if the length of the string * is bigger than expected (or I just don't know how to * use it properly ... TODO: research this). * * This case checks if the date is something like this: * Sun, 16 Feb 2014 18:44:57 -0300 (BRT) */ switch (length) { /* This case checks if the date is something like this: * Sun, 1 Feb 2014 18:44:57 -0300 (BRT) */ case (DATE_LENGTH_WITH_TZ - 1): dateWithCorrectSize = strDate.substring(0, DATE_LENGTH_WITHOUT_TZ - 1); break; /* This case checks if the date is something like this: * Sun, 16 Feb 2014 18:44:57 -0300 (BRT) */ case DATE_LENGTH_WITH_TZ: { dateWithCorrectSize = strDate.substring(0, DATE_LENGTH_WITHOUT_TZ); break; } /* This case checks if the date is something like this: * Sun, 6 Feb 2014 18:44:57 -0300 */ case (DATE_LENGTH_WITHOUT_TZ - 1): /* This case checks if the date is something like this: * Sun, 16 Feb 2014 18:44:57 -0300 */ case DATE_LENGTH_WITHOUT_TZ: { dateWithCorrectSize = strDate; break; } default: { if (length > DATE_LENGTH_WITH_TZ) { logger.warn("The length of the date header is bigger than expected: " + length); dateWithCorrectSize = strDate.substring(0, DATE_LENGTH_WITHOUT_TZ); } else { logger.error("The input date does not seem to be in any " + "recognizable format: " + strDate); logger.warn("Defaulting to epoch ..."); return new Date(0); } } } try { return DateUtils.parseDate(dateWithCorrectSize, "EEE, d MMM yyyy HH:mm:ss Z"); } catch (ParseException e) { logger.error("Unable to parse date " + strDate + ": " + e.getMessage(), e); logger.warn("Defaulting to epoch ..."); return new Date(0); } }
From source file:br.com.binarti.simplesearchexpr.SimpleSearchParserTest.java
@Test public void shouldParseSimpleSearchExpressionWithGroupOfFields() throws ParseException { SimpleSearchParser parser = new SimpleSearchParser( new SimpleSearchExpressionPlan(new SimpleSearchExpressionField("id", Integer.class), new SimpleSearchExpressionField("date", Date.class), new SimpleSearchExpressionField("value", Double.class), new SimpleSearchExpressionField("operationType", String.class))); SimpleSearchExpression expr = parser .parse("id:1 date:10/06/2014-13/06/2014 value:100.0 operationType:Input"); assertEquals(4, expr.getOperations().size()); SimpleSearchRelationalOperation relationalOperation = expr.getOperations().get(0); assertEquals("id", relationalOperation.getField().getName()); assertEquals(SimpleSearchRelationalOperator.EQUALS, relationalOperation.getOperator()); assertEquals(1, relationalOperation.getValue()); relationalOperation = expr.getOperations().get(1); assertEquals("date", relationalOperation.getField().getName()); assertEquals(SimpleSearchRelationalOperator.INTERVAL, relationalOperation.getOperator()); assertEquals(2, relationalOperation.getValueAsCollection().size()); assertArrayEquals(/*from w w w . j ava2 s .co m*/ asList(DateUtils.parseDate("10/06/2014", "dd/MM/yyyy"), DateUtils.parseDate("13/06/2014", "dd/MM/yyyy")).toArray(new Date[0]), relationalOperation.getValueAsCollection().toArray(new Date[0])); relationalOperation = expr.getOperations().get(2); assertEquals("value", relationalOperation.getField().getName()); assertEquals(SimpleSearchRelationalOperator.EQUALS, relationalOperation.getOperator()); assertEquals(new Double(100.0), relationalOperation.getValue()); relationalOperation = expr.getOperations().get(3); assertEquals("operationType", relationalOperation.getField().getName()); assertEquals(SimpleSearchRelationalOperator.LIKE, relationalOperation.getOperator()); assertEquals("Input", relationalOperation.getValue()); }
From source file:cn.mypandora.util.MyDateUtils.java
/** * //from w w w. j av a 2 s .c om * * @param date yyyy-MM * @return */ public static int getSpecifiedMonthDays(String date) { Calendar cal = Calendar.getInstance(); try { cal.setTime(DateUtils.parseDate(date, MONTH_FORMAT)); int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH); return days; } catch (Exception e1) { e1.printStackTrace(); } return 0; }
From source file:com.netsteadfast.greenstep.bsc.util.HistoryItemScoreReportContentQueryUtils.java
public static List<String> getLineChartCategories(String dateVal, int dataSize) throws Exception { List<String> categories = new LinkedList<String>(); if (dataSize < 0) { throw new ServiceException("data-size error!"); }/* www . j av a 2 s.c o m*/ Date endDate = DateUtils.parseDate(dateVal, new String[] { "yyyyMMdd" }); int dateRange = dataSize - 1; if (dateRange < 0) { dateRange = 0; } if (dateRange == 0) { categories.add(DateFormatUtils.format(endDate, "yyyy/MM/dd")); return categories; } Date startDate = DateUtils.addDays(endDate, (dateRange * -1)); for (int i = 0; i < dataSize; i++) { Date currentDate = DateUtils.addDays(startDate, i); String currentDateStr = DateFormatUtils.format(currentDate, "yyyy/MM/dd"); categories.add(currentDateStr); } return categories; }
From source file:com.creactiviti.piper.core.MapObject.java
@Override public Date getDate(Object aKey) { Object value = get(aKey);//from ww w.j a v a 2 s . co m if (value instanceof String) { try { return DateUtils.parseDate((String) value, TIMESTAMP_FORMAT); } catch (ParseException e) { throw Throwables.propagate(e); } } return (Date) value; }