List of usage examples for org.joda.time.format ISODateTimeFormat dateTimeParser
public static DateTimeFormatter dateTimeParser()
From source file:com.getperka.flatpack.codexes.DateCodex.java
License:Apache License
@Override public D readNotNull(JsonElement element, DeserializationContext context) throws Exception { if (element.isJsonPrimitive()) { long instant; JsonPrimitive primitive = element.getAsJsonPrimitive(); if (primitive.isNumber()) { instant = primitive.getAsLong(); } else {//from w w w .j a v a2s.c o m instant = ISODateTimeFormat.dateTimeParser().parseMillis(primitive.getAsString()); } return constructor.newInstance(instant); } throw new IllegalArgumentException("Could not parse " + element.toString() + " as a date value"); }
From source file:com.github.thorqin.toolkit.utility.StringUtils.java
public static DateTime parseISO8601(String dateTime) { DateTimeFormatter formatter = ISODateTimeFormat.dateTimeParser(); return formatter.parseDateTime(dateTime); }
From source file:com.helger.peppol.DateAdapter.java
License:Mozilla Public License
@Nullable public static LocalDateTime getLocalDateTimeFromXSD(@Nullable final String sValue) { final DateTimeFormatter aDTF = ISODateTimeFormat.dateTimeParser(); return PDTFromString.getLocalDateTimeFromString(sValue, aDTF); }
From source file:com.inbravo.scribe.rest.service.writer.utils.ConvertTimeZone.java
License:Open Source License
public static void main(String[] args) throws ParseException { DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser(); DateTime dateTimeHere = parser.parseDateTime("2012-10-31T17:25:54.478-07:00"); DateTime secondDateTime = dateTimeHere.withZone(DateTimeZone.forID("PST8PDT")); System.out.println("second: " + secondDateTime); }
From source file:com.linkedin.thirdeye.hadoop.ThirdEyeJob.java
License:Apache License
@SuppressWarnings("unchecked") public void run() throws Exception { LOGGER.info("Input config:{}", inputConfig); PhaseSpec phaseSpec;/*from www. j a v a2s . co m*/ try { phaseSpec = PhaseSpec.valueOf(phaseName.toUpperCase()); } catch (Exception e) { usage(); throw e; } if (PhaseSpec.TRANSFORM.equals(phaseSpec)) { TransformPhaseJob job = new TransformPhaseJob("Transform Job", inputConfig); job.run(); return; } else if (PhaseSpec.JOIN.equals(phaseSpec)) { JoinPhaseJob job = new JoinPhaseJob("Join Job", inputConfig); job.run(); return; } else if (PhaseSpec.WAIT.equals(phaseSpec)) { WaitPhaseJob job = new WaitPhaseJob("Wait for inputs", inputConfig); job.run(); return; } // Get root, collection, input paths String root = getAndCheck(ThirdEyeJobProperties.THIRDEYE_ROOT.getName(), inputConfig); String collection = getAndCheck(ThirdEyeJobProperties.THIRDEYE_COLLECTION.getName(), inputConfig); String inputPaths = getAndCheck(ThirdEyeJobProperties.INPUT_PATHS.getName(), inputConfig); // Get min / max time DateTime minTime; DateTime maxTime; String minTimeProp = inputConfig.getProperty(ThirdEyeJobProperties.THIRDEYE_TIME_MIN.getName()); String maxTimeProp = inputConfig.getProperty(ThirdEyeJobProperties.THIRDEYE_TIME_MAX.getName()); minTime = ISODateTimeFormat.dateTimeParser().parseDateTime(minTimeProp); maxTime = ISODateTimeFormat.dateTimeParser().parseDateTime(maxTimeProp); Properties jobProperties = phaseSpec.getJobProperties(inputConfig, root, collection, minTime, maxTime, inputPaths); for (Object key : inputConfig.keySet()) { jobProperties.setProperty(key.toString(), inputConfig.getProperty(key.toString())); } // Instantiate the job Constructor<Configured> constructor = (Constructor<Configured>) phaseSpec.getKlazz() .getConstructor(String.class, Properties.class); Configured instance = constructor.newInstance(phaseSpec.getName(), jobProperties); setMapreduceConfig(instance.getConf()); // Run the job Method runMethod = instance.getClass().getMethod("run"); Job job = (Job) runMethod.invoke(instance); if (job != null) { JobStatus status = job.getStatus(); if (status.getState() != JobStatus.State.SUCCEEDED) { throw new RuntimeException( "Job " + job.getJobName() + " failed to execute: Ran with config:" + jobProperties); } } }
From source file:com.lithium.yoda.ToEpoch.java
License:Apache License
@Override public Object evaluate(DeferredObject[] arguments) throws HiveException { if (dateOi instanceof StringObjectInspector) { String dateStr = ((StringObjectInspector) dateOi).getPrimitiveJavaObject(arguments[0].get()); DateTimeFormatter dtf;//from w w w . j a va 2 s .c om if (hasSecondArg) { if (constSecondArg == null) { dtf = DateTimeFormat.forPattern(formatOi.getPrimitiveJavaObject(arguments[1].get())); } else { dtf = DateTimeFormat.forPattern(constSecondArg); } } else { dtf = ISODateTimeFormat.dateTimeParser().withOffsetParsed(); } return dtf.parseDateTime(dateStr).getMillis(); } else if (dateOi instanceof TimestampObjectInspector) { Timestamp ts = ((TimestampObjectInspector) dateOi).getPrimitiveJavaObject(arguments[0].get()); if (hasSecondArg) { DateTime dt; if (constSecondArg == null) { dt = new DateTime(ts.getTime(), DateTimeZone.forID(formatOi.getPrimitiveJavaObject(arguments[1].get()))); } else { dt = new DateTime(ts.getTime(), DateTimeZone.forID(constSecondArg)); } return dt.getMillis(); } else { return ts.getTime(); } } return null; }
From source file:com.medvision360.medrecord.server.query.QueryEHRServerResource.java
License:Creative Commons License
protected DateTime getDateTimeQueryValue(String name) throws InvalidDateTimeException { String valueString = getQueryValue(name); if (valueString == null) { return null; }//ww w . jav a 2 s . co m try { DateTime parsed = ISODateTimeFormat.dateTimeParser().withZoneUTC().withOffsetParsed() .parseDateTime(valueString); return parsed; } catch (IllegalArgumentException e) { throw new InvalidDateTimeException(e.getMessage(), e); } }
From source file:com.quinsoft.zeidon.utils.JoeUtils.java
License:Open Source License
/** * Returns a DateTimeFormatter that can parse and print dates in the format of * editString. There can be multiple edit strings which are separated by a "|" * character. If there are more than one then the first one is considered to * be the "print" format./* www .j a va2s. co m*/ * * NOTE: Automatically adds ISO 8601 parser: 2016-11-29T05:41:02+00:00 * * @param editString * @return */ public static DateTimeFormatter createDateFormatterFromEditString(String editString) { String[] strings = editString.split("\\|"); DateTimeParser list[] = new DateTimeParser[strings.length + 1]; DateTimePrinter printer = null; for (int i = 0; i < strings.length; i++) { try { DateTimeFormatter f = DateTimeFormat.forPattern(strings[i]); if (printer == null) printer = f.getPrinter(); list[i] = f.getParser(); } catch (Exception e) { throw ZeidonException.wrapException(e).appendMessage("Format string = %s", strings[i]); } } list[strings.length] = ISODateTimeFormat.dateTimeParser().getParser(); DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); builder.append(printer, list); DateTimeFormatter formatter = builder.toFormatter(); return formatter; }
From source file:com.runwaysdk.controller.MojaxObjectParser.java
License:Open Source License
private Date parseDate(String dateTime) { try {/*from w w w. j av a 2s .c om*/ long timestamp = Long.parseLong(dateTime); return new Date(timestamp); } catch (NumberFormatException e) { // Expect date values to come in as timestamps. However, json.js uses // the ISO date format to serialized dates, so sometimes the // dates will be in that format instead of a timestamp. try { Date date = ISODateTimeFormat.dateTimeParser().parseDateTime(dateTime).toDate(); return date; } catch (Throwable t) { // Throw the original exception throw e; } } }
From source file:com.thinkbiganalytics.kylo.catalog.spark.sources.AbstractJdbcDataSetProvider.java
License:Apache License
/** * Creates a {@link JdbcHighWaterMark} using the specified high water mark. * * <p>The value is initialized using the {@link KyloCatalogClient}.</p> *///w ww . j av a2s . c o m @Nonnull @VisibleForTesting JdbcHighWaterMark createHighWaterMark(@Nonnull final String highWaterMarkKey, @Nonnull final KyloCatalogClient<T> client) { final JdbcHighWaterMark highWaterMark = new JdbcHighWaterMark(highWaterMarkKey, client); highWaterMark.setFormatter(new LongToDateTime()); // Set value final String value = client.getHighWaterMarks().get(highWaterMarkKey); if (value != null) { try { highWaterMark.accumulate(ISODateTimeFormat.dateTimeParser().withZoneUTC().parseMillis(value)); } catch (final IllegalArgumentException e) { throw new KyloCatalogException( "Invalid value for high water mark " + highWaterMarkKey + ": " + value, e); } } return highWaterMark; }