List of usage examples for org.joda.time.format DateTimeFormatter parseDateTime
public DateTime parseDateTime(String text)
From source file:nl.basjes.parse.dissectors.http.TimeStampDissector.java
License:Open Source License
@Override public void dissect(final Parsable<?> parsable, final String inputname) throws DissectionFailure { final ParsedField field = parsable.getParsableField(INPUT_TYPE, inputname); final String fieldValue = field.getValue(); if (fieldValue == null || fieldValue.isEmpty()) { return; // Nothing to do here }//from w ww .j ava 2 s . co m if (wantAnyAsParsed || wantAnyTZIndependent) { // FIXME: YUCK ! Parsing the same thing TWICE just for the Zone ?!?!? DateTime dateTime = asParsedFormatter.parseDateTime(fieldValue); DateTimeZone zone = dateTime.getZone(); DateTimeFormatter asParsedWithZoneFormatter = asParsedFormatter.withZone(zone); dateTime = asParsedWithZoneFormatter.parseDateTime(fieldValue); // As parsed if (wantDay) { parsable.addDissection(inputname, "TIME.DAY", "day", dateTime.dayOfMonth().getAsString()); } if (wantMonthname) { parsable.addDissection(inputname, "TIME.MONTHNAME", "monthname", dateTime.monthOfYear().getAsText(Locale.getDefault())); } if (wantMonth) { parsable.addDissection(inputname, "TIME.MONTH", "month", dateTime.monthOfYear().getAsString()); } if (wantWeekOfWeekYear) { parsable.addDissection(inputname, "TIME.WEEK", "weekofweekyear", dateTime.weekOfWeekyear().getAsString()); } if (wantWeekYear) { parsable.addDissection(inputname, "TIME.YEAR", "weekyear", dateTime.weekyear().getAsString()); } if (wantYear) { parsable.addDissection(inputname, "TIME.YEAR", "year", dateTime.year().getAsString()); } if (wantHour) { parsable.addDissection(inputname, "TIME.HOUR", "hour", dateTime.hourOfDay().getAsString()); } if (wantMinute) { parsable.addDissection(inputname, "TIME.MINUTE", "minute", dateTime.minuteOfHour().getAsString()); } if (wantSecond) { parsable.addDissection(inputname, "TIME.SECOND", "second", dateTime.secondOfMinute().getAsString()); } if (wantMillisecond) { parsable.addDissection(inputname, "TIME.MILLISECOND", "millisecond", dateTime.millisOfSecond().getAsString()); } // Timezone independent if (wantTimezone) { parsable.addDissection(inputname, "TIME.TIMEZONE", "timezone", dateTime.getZone().getID()); } if (wantEpoch) { parsable.addDissection(inputname, "TIME.EPOCH", "epoch", Long.toString(dateTime.getMillis())); } } if (wantAnyUTC) { // In UTC timezone DateTime dateTime = formatter.parseDateTime(fieldValue); if (wantDayUTC) { parsable.addDissection(inputname, "TIME.DAY", "day_utc", dateTime.dayOfMonth().getAsString()); } if (wantMonthnameUTC) { parsable.addDissection(inputname, "TIME.MONTHNAME", "monthname_utc", dateTime.monthOfYear().getAsText(Locale.getDefault())); } if (wantMonthUTC) { parsable.addDissection(inputname, "TIME.MONTH", "month_utc", dateTime.monthOfYear().getAsString()); } if (wantWeekOfWeekYearUTC) { parsable.addDissection(inputname, "TIME.WEEK", "weekofweekyear_utc", dateTime.weekOfWeekyear().getAsString()); } if (wantWeekYearUTC) { parsable.addDissection(inputname, "TIME.YEAR", "weekyear_utc", dateTime.weekyear().getAsString()); } if (wantYearUTC) { parsable.addDissection(inputname, "TIME.YEAR", "year_utc", dateTime.year().getAsString()); } if (wantHourUTC) { parsable.addDissection(inputname, "TIME.HOUR", "hour_utc", dateTime.hourOfDay().getAsString()); } if (wantMinuteUTC) { parsable.addDissection(inputname, "TIME.MINUTE", "minute_utc", dateTime.minuteOfHour().getAsString()); } if (wantSecondUTC) { parsable.addDissection(inputname, "TIME.SECOND", "second_utc", dateTime.secondOfMinute().getAsString()); } if (wantMillisecondUTC) { parsable.addDissection(inputname, "TIME.MILLISECOND", "millisecond_utc", dateTime.millisOfSecond().getAsString()); } } }
From source file:nl.basjes.parse.httpdlog.dissectors.TimeStampDissector.java
License:Apache License
@Override public void dissect(final Parsable<?> parsable, final String inputname) throws DissectionFailure { final ParsedField field = parsable.getParsableField(INPUT_TYPE, inputname); String fieldValue = field.getValue().getString(); if (fieldValue == null || fieldValue.isEmpty()) { return; // Nothing to do here }// ww w .j a v a2 s . c o m fieldValue = fieldValue.toLowerCase(Locale.getDefault()); if (wantAnyAsParsed || wantAnyTZIndependent) { // YUCK ! Parsing the same thing TWICE just for the Zone ?!?!? DateTime dateTime = asParsedFormatter.parseDateTime(fieldValue); DateTimeZone zone = dateTime.getZone(); DateTimeFormatter asParsedWithZoneFormatter = asParsedFormatter.withZone(zone); dateTime = asParsedWithZoneFormatter.parseDateTime(fieldValue); // As parsed if (wantDay) { parsable.addDissection(inputname, "TIME.DAY", "day", dateTime.dayOfMonth().get()); } if (wantMonthname) { parsable.addDissection(inputname, "TIME.MONTHNAME", "monthname", dateTime.monthOfYear().getAsText(Locale.getDefault())); } if (wantMonth) { parsable.addDissection(inputname, "TIME.MONTH", "month", dateTime.monthOfYear().get()); } if (wantWeekOfWeekYear) { parsable.addDissection(inputname, "TIME.WEEK", "weekofweekyear", dateTime.weekOfWeekyear().get()); } if (wantWeekYear) { parsable.addDissection(inputname, "TIME.YEAR", "weekyear", dateTime.weekyear().get()); } if (wantYear) { parsable.addDissection(inputname, "TIME.YEAR", "year", dateTime.year().get()); } if (wantHour) { parsable.addDissection(inputname, "TIME.HOUR", "hour", dateTime.hourOfDay().get()); } if (wantMinute) { parsable.addDissection(inputname, "TIME.MINUTE", "minute", dateTime.minuteOfHour().get()); } if (wantSecond) { parsable.addDissection(inputname, "TIME.SECOND", "second", dateTime.secondOfMinute().get()); } if (wantMillisecond) { parsable.addDissection(inputname, "TIME.MILLISECOND", "millisecond", dateTime.millisOfSecond().get()); } if (wantDate) { parsable.addDissection(inputname, "TIME.DATE", "date", ISO_DATE_FORMATTER.print(dateTime)); } if (wantTime) { parsable.addDissection(inputname, "TIME.TIME", "time", ISO_TIME_FORMATTER.print(dateTime)); } // Timezone independent if (wantTimezone) { parsable.addDissection(inputname, "TIME.TIMEZONE", "timezone", dateTime.getZone().getID()); } if (wantEpoch) { parsable.addDissection(inputname, "TIME.EPOCH", "epoch", dateTime.getMillis()); } } if (wantAnyUTC) { // In UTC timezone DateTime dateTime = formatter.parseDateTime(fieldValue); if (wantDayUTC) { parsable.addDissection(inputname, "TIME.DAY", "day_utc", dateTime.dayOfMonth().get()); } if (wantMonthnameUTC) { parsable.addDissection(inputname, "TIME.MONTHNAME", "monthname_utc", dateTime.monthOfYear().getAsText(Locale.getDefault())); } if (wantMonthUTC) { parsable.addDissection(inputname, "TIME.MONTH", "month_utc", dateTime.monthOfYear().get()); } if (wantWeekOfWeekYearUTC) { parsable.addDissection(inputname, "TIME.WEEK", "weekofweekyear_utc", dateTime.weekOfWeekyear().get()); } if (wantWeekYearUTC) { parsable.addDissection(inputname, "TIME.YEAR", "weekyear_utc", dateTime.weekyear().get()); } if (wantYearUTC) { parsable.addDissection(inputname, "TIME.YEAR", "year_utc", dateTime.year().get()); } if (wantHourUTC) { parsable.addDissection(inputname, "TIME.HOUR", "hour_utc", dateTime.hourOfDay().get()); } if (wantMinuteUTC) { parsable.addDissection(inputname, "TIME.MINUTE", "minute_utc", dateTime.minuteOfHour().get()); } if (wantSecondUTC) { parsable.addDissection(inputname, "TIME.SECOND", "second_utc", dateTime.secondOfMinute().get()); } if (wantMillisecondUTC) { parsable.addDissection(inputname, "TIME.MILLISECOND", "millisecond_utc", dateTime.millisOfSecond().get()); } if (wantDateUTC) { parsable.addDissection(inputname, "TIME.DATE", "date_utc", ISO_DATE_FORMATTER.print(dateTime)); } if (wantTimeUTC) { parsable.addDissection(inputname, "TIME.TIME", "time_utc", ISO_TIME_FORMATTER.print(dateTime)); } } }
From source file:nl.knaw.dans.dccd.oai.DCCDMetaDataService.java
License:Apache License
/** * get the timestamp for the latest change in the archive that OAI must know about. * /* ww w . j ava 2s . c o m*/ * @return */ public Date getLatestDate() { String xmlStr = getLastProjectXML(); if (xmlStr == null) return null; // now try to get the date from the XML // xpath would be: /projects/project/stateChanged // use DOM parser try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new InputSource(new StringReader(xmlStr))); NodeList nodes = doc.getElementsByTagName("stateChanged"); // should be one and only one! Element element = (Element) nodes.item(0); String dateStr = element.getTextContent(); // convert to a date DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); return fmt.parseDateTime(dateStr).toDate(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:nl.knaw.dans.dccd.rest.ProjectResource.java
License:Apache License
private void addFilterQueryForModified(SimpleSearchRequest request, final String modFromStr, final String modUntilStr) throws IllegalArgumentException { DateTimeWrapper modFrom = null;//from w w w. j a v a 2 s . c om DateTimeWrapper modUntil = null; // parse the strings an get DateTime objects // Note that it should be the same format as we use when outputting the "stateChanged" property. if (modFromStr != null) { DateTimeFormatter df = ISODateTimeFormat.dateTime(); modFrom = new DateTimeWrapper(df.parseDateTime(modFromStr)); } if (modUntilStr != null) { DateTimeFormatter df = ISODateTimeFormat.dateTime(); modUntil = new DateTimeWrapper(df.parseDateTime(modUntilStr)); } if (modFrom != null || modUntil != null) { // use DccdProjectSB.ADMINISTRATIVE_STATE_LASTCHANGE // Note that for Published (aka Archived) projects this is the timestamp for the publishing. // Draft projects can be modified without the 'change of state', but we won't expose those. SimpleField<Range<DateTimeWrapper>> periodField = new SimpleField<Range<DateTimeWrapper>>( DccdProjectSB.ADMINISTRATIVE_STATE_LASTCHANGE); periodField.setValue(new Range<DateTimeWrapper>(modFrom, modUntil)); request.addFilterQuery(periodField); } }
From source file:no.digipost.android.utilities.FileUtilities.java
License:Apache License
private static String getAttachmentFullFilename() { String fileType = DocumentContentStore.getDocumentAttachment().getFileType(); String creatorName = DocumentContentStore.getDocumentParent().getCreatorName(); String fileName = DocumentContentStore.getDocumentAttachment().getSubject(); String dateCreated = ""; try {//from w w w . j a v a 2s .c o m String tempDate = DocumentContentStore.getDocumentParent().getCreated(); DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); DateTime jodatime = dtf.parseDateTime(tempDate); DateTimeFormatter dtfOut = DateTimeFormat.forPattern("yyyy.MM.dd"); dateCreated = dtfOut.print(jodatime) + " "; } catch (Exception e) { } String fullFileName = (dateCreated + creatorName.toUpperCase() + " " + fileName + "." + fileType); fullFileName = fullFileName.replaceAll("[()\\?:!,;{}-]+", "").replaceAll("[\\t\\n\\s]+", "_"); return fullFileName; }
From source file:nu.yona.app.ui.message.AdminNotificationFragment.java
private String getTime(String date) { String pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern); DateTime dateTime = dtf.parseDateTime(date); return dateTime.getHourOfDay() + ":" + dateTime.getMinuteOfHour(); }
From source file:nz.co.jsrsolutions.ds3.provider.CMEEodDataProviderCsvParser.java
License:Open Source License
public void parse(InputStream inputStream) throws EodDataProviderException { String line;// w w w .ja va 2 s. co m BufferedReader br; @SuppressWarnings("unused") int lineNumber = 1; // skip the header try { br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); line = br.readLine(); // skip the first line (header) while ((line = br.readLine()) != null) { ++lineNumber; // use comma as separator String[] columns = line.split(","); SYMBOL symbol = new SYMBOL(); symbol.setCode(columns[4]); // CONTRACT symbol.setName(columns[4]); // CONTRACT symbol.setLongName(columns[5]); // PRODUCT DESCRIPTION _symbols.add(symbol); // if there is no settlement for this contract // then ignore this quote if (columns[13].isEmpty()) { continue; } QUOTE quote = new QUOTE(); quote.setSymbol(columns[4]); // CONTRACT quote.setName(columns[4]); // CONTRACT quote.setDescription(columns[5]); // PRODUCT DESCRIPTION if (columns[6].isEmpty()) { quote.setOpen(Double.parseDouble(columns[13])); // SETTLE(?) } else { quote.setOpen(Double.parseDouble(columns[6])); // OPEN } if (columns[11].isEmpty()) { quote.setClose(Double.parseDouble(columns[13])); // SETTLE(?) } else { quote.setClose(Double.parseDouble(columns[11])); // CLOSE } String high = columns[7]; String low = columns[9]; if (!high.isEmpty()) { quote.setHigh(Double.parseDouble(high)); } if (!low.isEmpty()) { quote.setLow(Double.parseDouble(low)); } quote.setVolume(Long.parseLong(columns[15])); if (columns[14].equals("UNCH")) { quote.setChange(0.0); } else { quote.setChange(Double.parseDouble(columns[14])); } quote.setOpenInterest(Long.parseLong(columns[15])); DateTimeFormatter formatter = DateTimeFormat.forPattern("MM/dd/yyyy"); DateTime dt = formatter.parseDateTime(columns[19]); quote.setDateTime(dt.toGregorianCalendar()); _quotes.add(quote); } } catch (UnsupportedEncodingException e) { throw new EodDataProviderException(e); } catch (IOException e) { throw new EodDataProviderException(e); } }
From source file:op.tools.SYSCalendar.java
License:Open Source License
/** * determines to which timeofday code a given date object belongs. The settings in SYSProps are taken into account. * or in short: it answers a question like "is 0800h early, noon or early in the morning ?" * * @param date//from w w w .ja v a 2 s .c o m * @return timecode */ public static byte whatTimeIDIs(Date date) { byte timeid; DateTimeFormatter parser = DateTimeFormat.forPattern("HH:mm"); DateTime early_in_the_morning = parser .parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_EARLY_IN_THE_MORNING)); DateTime morning = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_MORNING)); DateTime noon = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_NOON)); DateTime afternoon = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_AFTERNOON)); DateTime evening = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_EVENING)); DateTime late_at_night = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_LATE_AT_NIGHT)); Period period_early_in_the_morning = new Period(early_in_the_morning.getHourOfDay(), early_in_the_morning.getMinuteOfHour(), early_in_the_morning.getSecondOfMinute(), early_in_the_morning.getMillisOfSecond()); Period period_morning = new Period(morning.getHourOfDay(), morning.getMinuteOfHour(), morning.getSecondOfMinute(), morning.getMillisOfSecond()); Period period_noon = new Period(noon.getHourOfDay(), noon.getMinuteOfHour(), noon.getSecondOfMinute(), noon.getMillisOfSecond()); Period period_afternoon = new Period(afternoon.getHourOfDay(), afternoon.getMinuteOfHour(), afternoon.getSecondOfMinute(), afternoon.getMillisOfSecond()); Period period_evening = new Period(evening.getHourOfDay(), evening.getMinuteOfHour(), evening.getSecondOfMinute(), evening.getMillisOfSecond()); Period period_late_at_night = new Period(late_at_night.getHourOfDay(), late_at_night.getMinuteOfHour(), late_at_night.getSecondOfMinute(), late_at_night.getMillisOfSecond()); DateTime ref = new DateTime(date); DateTime eitm = new DateMidnight(date).toDateTime().plus(period_early_in_the_morning); DateTime m = new DateMidnight(date).toDateTime().plus(period_morning); DateTime n = new DateMidnight(date).toDateTime().plus(period_noon); DateTime a = new DateMidnight(date).toDateTime().plus(period_afternoon); DateTime e = new DateMidnight(date).toDateTime().plus(period_evening); DateTime lan = new DateMidnight(date).toDateTime().plus(period_late_at_night); if (eitm.compareTo(ref) <= 0 && ref.compareTo(m) < 0) { timeid = DFNTools.BYTE_EARLY_IN_THE_MORNING; } else if (m.compareTo(ref) <= 0 && ref.compareTo(n) < 0) { timeid = DFNTools.BYTE_MORNING; } else if (n.compareTo(ref) <= 0 && ref.compareTo(a) < 0) { timeid = DFNTools.BYTE_NOON; } else if (a.compareTo(ref) <= 0 && ref.compareTo(e) < 0) { timeid = DFNTools.BYTE_AFTERNOON; } else if (e.compareTo(ref) <= 0 && ref.compareTo(lan) < 0) { timeid = DFNTools.BYTE_EVENING; } else { timeid = DFNTools.BYTE_LATE_AT_NIGHT; } return timeid; }
From source file:org.activiti.rest.content.service.api.BaseSpringContentRestTestCase.java
License:Apache License
/** * Extract a date from the given string. Assertion fails when invalid date has been provided. *//* ww w. j av a2s . c om*/ protected Date getDateFromISOString(String isoString) { DateTimeFormatter dateFormat = ISODateTimeFormat.dateTime(); try { return dateFormat.parseDateTime(isoString).toDate(); } catch (IllegalArgumentException iae) { fail("Illegal date provided: " + isoString); return null; } }
From source file:org.adl.datamodels.datatypes.DateTimeValidatorImpl.java
/** * Compares two valid data model elements for equality. * /* w w w. j ava 2 s . c o m*/ * @param iFirst The first value being compared. * * @param iSecond The second value being compared. * * @param iDelimiters The common set of delimiters associated with the * values being compared. * * @return Returns <code>true</code> if the two values are equal, otherwise * <code>false</code>. */ @Override public boolean compare(String iFirst, String iSecond, List<DMDelimiter> iDelimiters) { boolean equal = true; DateTimeFormatter dtp = ISODateTimeFormat.dateTimeParser(); try { // Parse the first string and remove the sub-seconds DateTime dt1 = dtp.parseDateTime(iFirst); dt1 = new DateTime(dt1.getYear(), dt1.getMonthOfYear(), dt1.getDayOfMonth(), dt1.getHourOfDay(), dt1.getMinuteOfHour(), dt1.getSecondOfMinute(), 0); // Parse the second string and remove the sub-seconds DateTime dt2 = dtp.parseDateTime(iSecond); dt2 = new DateTime(dt2.getYear(), dt2.getMonthOfYear(), dt2.getDayOfMonth(), dt2.getHourOfDay(), dt2.getMinuteOfHour(), dt2.getSecondOfMinute(), 0); equal = dt1.equals(dt2); } catch (Exception e) { // String format error -- these cannot be equal equal = false; } return equal; }