Example usage for org.joda.time.format DateTimeFormatter parseDateTime

List of usage examples for org.joda.time.format DateTimeFormatter parseDateTime

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormatter parseDateTime.

Prototype

public DateTime parseDateTime(String text) 

Source Link

Document

Parses a date-time from the given text, returning a new DateTime.

Usage

From source file:org.apache.falcon.regression.core.util.TimeUtil.java

License:Apache License

public static String addMinsToTime(String time, int minutes) {

    DateTimeFormatter fmt = OozieUtil.getOozieDateTimeFormatter();
    DateTime jodaTime = fmt.parseDateTime(time);
    jodaTime = jodaTime.plusMinutes(minutes);
    return fmt.print(jodaTime);
}

From source file:org.apache.falcon.regression.core.util.TimeUtil.java

License:Apache License

public static DateTime oozieDateToDate(String time) {
    DateTimeFormatter fmt = OozieUtil.getOozieDateTimeFormatter();
    fmt = fmt.withZoneUTC();/*from   w ww.j ava  2  s.c o  m*/
    return fmt.parseDateTime(time);
}

From source file:org.apache.falcon.regression.ui.search.ProcessWizardPage.java

License:Apache License

/**
 * Method gets text from summary box and parses it to ProcessMerlin object.
 * @param draft empty ProcessMerlin object
 *//*  ww w .  ja v a  2 s . c o  m*/
public ProcessMerlin getProcessFromSummaryBox(ProcessMerlin draft) {
    String text = summaryBox.getText().trim();
    draft.setName(getProperty(text, null, "Tags", 2));
    String currentBlock = text.substring(text.indexOf("Tags"), text.indexOf("Access Control List"));
    String[] parts;
    parts = currentBlock.trim().split("\\n");
    String tags = "";
    for (int i = 1; i < parts.length; i++) {
        String tag = parts[i];
        if (!tag.contains("No tags")) {
            tag = tag.replace(" ", "");
            tags = tags + (tags.isEmpty() ? tag : "," + tag);
        }
    }
    if (!tags.isEmpty()) {
        draft.setTags(tags);
    }

    Workflow workflow = new Workflow();
    workflow.setName(getProperty(text, "Workflow", "Engine", 2));
    workflow.setEngine(EngineType.fromValue(getProperty(text, "Engine", "Version", 1)));
    workflow.setVersion(getProperty(text, "Version", "Path", 1));
    workflow.setPath(getProperty(text, "Path", "Timing", 1));
    draft.setWorkflow(workflow);

    draft.setTimezone(TimeZone.getTimeZone(getProperty(text, "Timing", "Frequency", 2)));
    parts = getProperty(text, "Frequency", "Max. parallel instances", 1).split(" ");
    draft.setFrequency(new Frequency(parts[1], Frequency.TimeUnit.valueOf(parts[2])));
    draft.setParallel(Integer.parseInt(getProperty(text, "Max. parallel instances", "Order", 1)));
    draft.setOrder(ExecutionType.fromValue(getProperty(text, "Order", "Retry", 1)));

    String aclOwner = getProperty(text, "Owner", "Group", 1);
    String aclGroup = getProperty(text, "Group", "Permissions", 1);
    String aclPermission = getProperty(text, "Permissions", "Workflow", 1);
    draft.setACL(aclOwner, aclGroup, aclPermission);

    Retry retry = new Retry();
    retry.setPolicy(PolicyType.fromValue(getProperty(text, "Retry", "Attempts", 2)));
    retry.setAttempts(Integer.parseInt(getProperty(text, "Attempts", "Delay", 1)));
    parts = getProperty(text, "Delay", "Clusters", 1).split(" ");
    retry.setDelay(new Frequency(parts[2], Frequency.TimeUnit.valueOf(parts[3])));
    draft.setRetry(retry);

    //get clusters
    currentBlock = text.substring(text.indexOf("Clusters"), text.indexOf("Inputs"));
    int last = 0;
    while (last != -1) {
        Cluster cluster = new Cluster();
        cluster.setName(getProperty(currentBlock, "Name", "Validity", 1));
        //remove the part which was used
        currentBlock = currentBlock.substring(currentBlock.indexOf("Validity"));
        //get validity
        String start = getProperty(currentBlock, "Validity", "End", 2);
        //check if there are other clusters
        last = currentBlock.indexOf("Name");
        String innerBlock = currentBlock
                .substring(currentBlock.indexOf("End"), last != -1 ? last : currentBlock.length() - 1).trim();
        String end = innerBlock.trim().split("\\n")[1];
        Validity validity = new Validity();
        DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy'-'MM'-'dd' 'HH':'mm'");
        validity.setStart(formatter.parseDateTime(start.replaceAll("\"", "")).toDate());
        validity.setEnd(formatter.parseDateTime(end.replaceAll("\"", "")).toDate());
        cluster.setValidity(validity);
        draft.getClusters().getClusters().add(cluster);
    }
    //get inputs
    currentBlock = text.substring(text.indexOf("Inputs"), text.indexOf("Outputs"));
    last = 0;
    while (last != -1) {
        Input input = new Input();
        //get input name
        input.setName(getProperty(currentBlock, "Name", "Feed", 1));
        //remove the part which was used
        currentBlock = currentBlock.substring(currentBlock.indexOf("Name") + 4);
        //get input feed
        input.setFeed(getProperty(currentBlock, "Feed", "Instance", 1));
        //get input start
        input.setStart(getProperty(currentBlock, "Instance", "End", 2));
        //get input end
        last = currentBlock.indexOf("Name");
        String innerBlock = currentBlock
                .substring(currentBlock.indexOf("End"), last != -1 ? last : currentBlock.length() - 1).trim();
        parts = innerBlock.trim().split("\\n");
        input.setEnd(parts[1]);
        draft.getInputs().getInputs().add(input);
        //remove part which was parsed
        currentBlock = currentBlock.substring(currentBlock.indexOf("End") + 4);
    }
    //get outputs
    currentBlock = text.substring(text.indexOf("Outputs"));
    last = 0;
    while (last != -1) {
        Output output = new Output();
        output.setName(getProperty(currentBlock, "Name", "Feed", 1));
        //remove the part which was used
        currentBlock = currentBlock.substring(currentBlock.indexOf("Feed"));
        //get feed
        output.setFeed(getProperty(currentBlock, "Feed", "Instance", 1));
        last = currentBlock.indexOf("Name");
        output.setInstance(getProperty(currentBlock, "Instance", "Name", 2));
        draft.getOutputs().getOutputs().add(output);
    }
    //check compulsory process properties
    Assert.assertNotNull(draft.getACL(), "ACL is empty (null).");
    return draft;
}

From source file:org.apache.gobblin.compaction.parser.CompactionPathParser.java

License:Apache License

private DateTime getTime(String timeString) {
    DateTimeZone timeZone = DateTimeZone.forID(MRCompactor.DEFAULT_COMPACTION_TIMEZONE);
    int splits = StringUtils.countMatches(timeString, "/");
    String timePattern = "";
    if (splits == 3) {
        timePattern = "YYYY/MM/dd/HH";
    } else if (splits == 2) {
        timePattern = "YYYY/MM/dd";
    }/* w  w w .j  av a  2  s .  c  o m*/
    DateTimeFormatter timeFormatter = DateTimeFormat.forPattern(timePattern).withZone(timeZone);
    return timeFormatter.parseDateTime(timeString);
}

From source file:org.apache.gobblin.ingestion.google.webmaster.GoogleWebmasterExtractor.java

License:Apache License

/**
 * For test only/*from  w w w  .  ja  v a  2s .c o  m*/
 */
GoogleWebmasterExtractor(WorkUnitState wuState, long lowWatermark, long expectedHighWaterMark,
        Map<String, Integer> columnPositionMap, List<GoogleWebmasterFilter.Dimension> requestedDimensions,
        List<GoogleWebmasterDataFetcher.Metric> requestedMetrics, JsonArray schemaJson,
        List<GoogleWebmasterDataFetcher> dataFetchers) {
    DateTimeFormatter watermarkFormatter = DateTimeFormat.forPattern("yyyyMMddHHmmss");
    _startDate = watermarkFormatter.parseDateTime(Long.toString(lowWatermark));
    _expectedHighWaterMark = expectedHighWaterMark;
    _expectedHighWaterMarkDate = watermarkFormatter.parseDateTime(Long.toString(expectedHighWaterMark));
    log.info(String.format("Creating GoogleWebmasterExtractor for [%s, %s] for job %s.", _startDate.toString(),
            _expectedHighWaterMarkDate.toString(), wuState.getProp(ConfigurationKeys.SOURCE_ENTITY)));

    _wuState = wuState;
    _schema = schemaJson;
    _includeSource = wuState.getWorkunit().getPropAsBoolean(GoogleWebMasterSource.KEY_INCLUDE_SOURCE_PROPERTY,
            GoogleWebMasterSource.DEFAULT_INCLUDE_SOURCE_PROPERTY);

    Iterable<Map<GoogleWebmasterFilter.Dimension, ApiDimensionFilter>> filterGroups = getFilterGroups(wuState);

    for (GoogleWebmasterDataFetcher dataFetcher : dataFetchers) {
        for (Map<GoogleWebmasterFilter.Dimension, ApiDimensionFilter> filters : filterGroups) {
            List<GoogleWebmasterFilter.Dimension> actualDimensionRequests = new ArrayList<>(
                    requestedDimensions);
            //Need to remove the dimension from actualDimensionRequests if the filter for that dimension is ALL/Aggregated
            for (Map.Entry<GoogleWebmasterFilter.Dimension, ApiDimensionFilter> filter : filters.entrySet()) {
                if (filter.getValue() == null) {
                    actualDimensionRequests.remove(filter.getKey());
                }
            }
            String startDate = dateFormatter.print(_startDate);
            String endDate = dateFormatter.print(_expectedHighWaterMarkDate);
            GoogleWebmasterExtractorIterator iterator = new GoogleWebmasterExtractorIterator(dataFetcher,
                    startDate, endDate, actualDimensionRequests, requestedMetrics, filters, wuState);
            log.info("Created " + iterator.toString());
            // positionMapping is to address the cases when requested dimensions/metrics order
            // is different from the column order in source.schema
            int[] positionMapping = new int[actualDimensionRequests.size() + requestedMetrics.size()];
            int i = 0;
            for (; i < actualDimensionRequests.size(); ++i) {
                positionMapping[i] = columnPositionMap.get(actualDimensionRequests.get(i).toString());
            }
            for (GoogleWebmasterDataFetcher.Metric requestedMetric : requestedMetrics) {
                positionMapping[i++] = columnPositionMap.get(requestedMetric.toString());
            }
            //One positionMapping is corresponding to one iterator.
            _iterators.add(iterator);
            _positionMaps.add(positionMapping);
        }
    }
}

From source file:org.apache.phoenix.pherf.rules.RulesApplier.java

License:Apache License

public String generateRandomDate(String min, String max) throws Exception {
    DateTimeFormatter fmtr = DateTimeFormat.forPattern(PherfConstants.DEFAULT_DATE_PATTERN)
            .withZone(DateTimeZone.UTC);
    DateTime minDt;/*from   w  w  w.j a va2 s  . co m*/
    DateTime maxDt;
    DateTime dt;

    minDt = fmtr.parseDateTime(checkDatePattern(min));
    maxDt = fmtr.parseDateTime(checkDatePattern(max));

    // Get Ms Date between min and max
    synchronized (randomDataGenerator) {
        //Make sure date generated is exactly between the passed limits
        long rndLong = randomDataGenerator.nextLong(minDt.getMillis() + 1, maxDt.getMillis() - 1);
        dt = new DateTime(rndLong, PherfConstants.DEFAULT_TIME_ZONE);
    }

    return fmtr.print(dt);
}

From source file:org.apache.phoenix.pherf.rules.RulesApplier.java

License:Apache License

public String checkDatePattern(String date) {
    DateTimeFormatter fmtr = DateTimeFormat.forPattern(PherfConstants.DEFAULT_DATE_PATTERN)
            .withZone(DateTimeZone.UTC);
    ;// w w w  .ja v  a  2 s . c om
    DateTime parsedDate = fmtr.parseDateTime(date);
    return fmtr.print(parsedDate);
}

From source file:org.apache.pig.builtin.ToDate2ARGS.java

License:Apache License

public DateTime exec(Tuple input) throws IOException {
    if (input == null || input.size() < 1 || input.get(0) == null) {
        return null;
    }//from  w  ww  .j a v a2s. c o  m
    String dtStr = DataType.toString(input.get(0));
    //DateTimeZone dtz = extractDateTimeZone(dtStr);
    //The timezone in the customized format is not predictable
    DateTimeFormatter dtf = DateTimeFormat.forPattern(DataType.toString(input.get(1)));
    //if (dtz == null) {
    return dtf.parseDateTime(dtStr);
    //} else {
    //    return dtf.withZone(dtz).parseDateTime(dtStr);
    //}
}

From source file:org.apache.pig.piggybank.evaluation.datetime.convert.CustomFormatToISO.java

License:Apache License

@Override
public String exec(Tuple input) throws IOException {
    if (input == null || input.size() < 2) {
        return null;
    }//from  w w  w.  j a va 2 s .  c  om

    // Set the time to default or the output is in UTC
    DateTimeZone.setDefault(DateTimeZone.UTC);

    String date = input.get(0).toString();
    String format = input.get(1).toString();

    // See http://joda-time.sourceforge.net/api-release/org/joda/time/format/DateTimeFormat.html
    DateTimeFormatter parser = DateTimeFormat.forPattern(format);
    DateTime result;
    try {
        result = parser.parseDateTime(date);
    } catch (Exception e) {
        return null;
    }

    return result.toString();
}

From source file:org.apache.rave.portal.util.ModelUtil.java

License:Apache License

public static Date stringToDate(String dateString) {
    DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis();
    return fmt.parseDateTime(dateString).toDate();
}