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

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

Introduction

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

Prototype

public String print(ReadablePartial partial) 

Source Link

Document

Prints a ReadablePartial to a new String.

Usage

From source file:org.apache.archiva.webdav.ArchivaVirtualDavResource.java

License:Apache License

/**
 * Fill the set of properties/*from   w  ww  . ja va 2  s.co  m*/
 */
protected void initProperties() {
    if (!exists() || propsInitialized) {
        return;
    }

    // set (or reset) fundamental properties
    if (getDisplayName() != null) {
        properties.add(new DefaultDavProperty(DavPropertyName.DISPLAYNAME, getDisplayName()));
    }
    if (isCollection()) {
        properties.add(new ResourceType(ResourceType.COLLECTION));
        // Windows XP support
        properties.add(new DefaultDavProperty(DavPropertyName.ISCOLLECTION, "1"));
    } else {
        properties.add(new ResourceType(ResourceType.DEFAULT_RESOURCE));

        // Windows XP support
        properties.add(new DefaultDavProperty(DavPropertyName.ISCOLLECTION, "0"));
    }

    // Need to get the ISO8601 date for properties
    DateTime dt = new DateTime(0);
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    String modifiedDate = fmt.print(dt);

    properties.add(new DefaultDavProperty(DavPropertyName.GETLASTMODIFIED, modifiedDate));

    properties.add(new DefaultDavProperty(DavPropertyName.CREATIONDATE, modifiedDate));

    properties.add(new DefaultDavProperty(DavPropertyName.GETCONTENTLENGTH, 0));

    propsInitialized = true;
}

From source file:org.apache.druid.indexer.path.GranularityPathSpec.java

License:Apache License

@Override
public Job addInputPaths(HadoopDruidIndexerConfig config, Job job) throws IOException {
    final Set<Interval> intervals = new TreeSet<>(Comparators.intervalsByStartThenEnd());
    for (Interval inputInterval : config.getInputIntervals()) {
        for (Interval interval : dataGranularity.getIterable(inputInterval)) {
            intervals.add(trim(inputInterval, interval));
        }//from   w  w w . j  av a 2s .co  m
    }

    Path betaInput = new Path(inputPath);
    FileSystem fs = betaInput.getFileSystem(job.getConfiguration());
    Set<String> paths = new TreeSet<>();
    Pattern fileMatcher = Pattern.compile(filePattern);

    DateTimeFormatter customFormatter = null;
    if (pathFormat != null) {
        customFormatter = DateTimeFormat.forPattern(pathFormat);
    }

    for (Interval interval : intervals) {
        DateTime t = interval.getStart();
        String intervalPath;
        if (customFormatter != null) {
            intervalPath = customFormatter.print(t);
        } else {
            intervalPath = dataGranularity.toPath(t);
        }

        Path granularPath = new Path(betaInput, intervalPath);
        log.info("Checking path[%s]", granularPath);
        for (FileStatus status : FSSpideringIterator.spiderIterable(fs, granularPath)) {
            final Path filePath = status.getPath();
            if (fileMatcher.matcher(filePath.toString()).matches()) {
                paths.add(filePath.toString());
            }
        }
    }

    log.info("Appending path %s", paths);
    StaticPathSpec.addToMultipleInputs(config, job, paths, inputFormat);

    return job;
}

From source file:org.apache.druid.query.expression.TimestampFormatExprMacro.java

License:Apache License

@Override
public Expr apply(final List<Expr> args) {
    if (args.size() < 1 || args.size() > 3) {
        throw new IAE("Function[%s] must have 1 to 3 arguments", name());
    }//from  w  w  w.j a v  a 2  s.  c o  m

    final Expr arg = args.get(0);
    final String formatString;
    final DateTimeZone timeZone;

    if (args.size() > 1) {
        Preconditions.checkArgument(args.get(1).isLiteral(), "Function[%s] format arg must be a literal",
                name());
        formatString = (String) args.get(1).getLiteralValue();
    } else {
        formatString = null;
    }

    if (args.size() > 2) {
        timeZone = ExprUtils.toTimeZone(args.get(2));
    } else {
        timeZone = DateTimeZone.UTC;
    }

    final DateTimeFormatter formatter = formatString == null ? ISODateTimeFormat.dateTime()
            : DateTimeFormat.forPattern(formatString).withZone(timeZone);

    class TimestampFormatExpr extends ExprMacroTable.BaseScalarUnivariateMacroFunctionExpr {
        private TimestampFormatExpr(Expr arg) {
            super(arg);
        }

        @Nonnull
        @Override
        public ExprEval eval(final ObjectBinding bindings) {
            ExprEval eval = arg.eval(bindings);
            if (eval.isNumericNull()) {
                // Return null if the argument if null.
                return ExprEval.of(null);
            }
            return ExprEval.of(formatter.print(arg.eval(bindings).asLong()));
        }

        @Override
        public Expr visit(Shuttle shuttle) {
            Expr newArg = arg.visit(shuttle);
            return shuttle.visit(new TimestampFormatExpr(newArg));
        }
    }

    return new TimestampFormatExpr(arg);
}

From source file:org.apache.falcon.oozie.process.NativeOozieProcessWorkflowBuilder.java

License:Apache License

@Override
public java.util.Properties build(Cluster cluster, Path buildPath, Properties suppliedProps)
        throws FalconException {
    Properties elProps = new Properties();
    DateTimeFormatter fmt = DateTimeFormat.forPattern(INSTANCE_FORMAT);
    elProps.put(WorkflowExecutionArgs.NOMINAL_TIME.getName(), fmt.print(getNominalTime()));
    elProps.put(WorkflowExecutionArgs.TIMESTAMP.getName(), fmt.print(getNominalTime()));
    elProps.put(WorkflowExecutionArgs.USER_JMS_NOTIFICATION_ENABLED.getName(), "true");
    elProps.put(WorkflowExecutionArgs.SYSTEM_JMS_NOTIFICATION_ENABLED.getName(), "false"); //check true or false

    DateUtil.setTimeZone(entity.getTimezone().getID());
    ExpressionHelper.setReferenceDate(new Date(getNominalTime().getMillis()));
    elProps.putAll(getInputProps(cluster));
    elProps.putAll(getOutputProps());/*from  w w  w.  j av  a 2s.  c  o  m*/
    elProps.putAll(evalProperties());
    Properties buildProps = build(cluster, buildPath);
    buildProps.putAll(elProps);
    copyPropsWithoutOverride(buildProps, suppliedProps);
    return buildProps;
}

From source file:org.apache.falcon.regression.core.bundle.Bundle.java

License:Apache License

public void setProcessValidity(DateTime startDate, DateTime endDate) {

    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd/HH:mm");

    String start = formatter.print(startDate).replace("/", "T") + "Z";
    String end = formatter.print(endDate).replace("/", "T") + "Z";

    ProcessMerlin processElement = new ProcessMerlin(processData);

    for (Cluster cluster : processElement.getClusters().getClusters()) {

        org.apache.falcon.entity.v0.process.Validity validity = new org.apache.falcon.entity.v0.process.Validity();
        validity.setStart(TimeUtil.oozieDateToDate(start).toDate());
        validity.setEnd(TimeUtil.oozieDateToDate(end).toDate());
        cluster.setValidity(validity);/* ww w  .j  a  v a 2  s . com*/

    }

    processData = processElement.toString();
}

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

License:Apache License

public static List<String> getMinuteDatesOnEitherSide(DateTime startDate, DateTime endDate, int minuteSkip,
        DateTimeFormatter formatter) {
    LOGGER.info("generating data between " + formatter.print(startDate) + " and " + formatter.print(endDate));
    if (minuteSkip == 0) {
        minuteSkip = 1;/*from w  ww  .jav  a 2  s  . com*/
    }
    List<String> dates = new ArrayList<>();
    while (!startDate.isAfter(endDate)) {
        dates.add(formatter.print(startDate));
        startDate = startDate.plusMinutes(minuteSkip);
    }
    return dates;
}

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

License:Apache License

/**
 * Convert list of dates to list of string according to the supplied format.
 *
 * @param dates        list of dates//from   w  w  w. j a  v  a  2 s. c om
 * @param formatter formatter to be used for converting dates
 * @return list of strings corresponding to given dates
 */
public static List<String> convertDatesToString(List<DateTime> dates, DateTimeFormatter formatter) {
    List<String> dateString = new ArrayList<>();
    formatter.withZoneUTC();
    for (DateTime date : dates) {
        dateString.add(formatter.print(date));
    }
    return dateString;
}

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

License:Apache License

public static String getTimeWrtSystemTime(int minutes) {

    DateTime jodaTime = new DateTime(DateTimeZone.UTC);
    if (minutes > 0) {
        jodaTime = jodaTime.plusMinutes(minutes);
    } else {//w w w  .java  2  s .c  om
        jodaTime = jodaTime.minusMinutes(-1 * minutes);
    }
    DateTimeFormatter fmt = OozieUtil.getOozieDateTimeFormatter();
    DateTimeZone tz = DateTimeZone.getDefault();
    return fmt.print(tz.convertLocalToUTC(jodaTime.getMillis(), false));
}

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 String dateToOozieDate(Date dt) {

    DateTime jodaTime = new DateTime(dt, DateTimeZone.UTC);
    LOGGER.info("SystemTime: " + jodaTime);
    DateTimeFormatter fmt = OozieUtil.getOozieDateTimeFormatter();
    return fmt.print(jodaTime);
}