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:name.martingeisse.common.javascript.JavascriptAssembler.java

License:Open Source License

/**
 * Uses the specified Joda-Time instant and formatter to append a string literal.
 * //from  w  ww  .j av a2  s .  co m
 * @param value the instant to append
 * @param formatter the formatter used to turn the instant into a string
 * @return this
 */
public final JavascriptAssembler appendJodaLiteral(ReadableInstant value, DateTimeFormatter formatter) {
    if (value == null) {
        throw new IllegalArgumentException("value argument is null");
    }
    appendStringLiteral(formatter.print(value));
    return this;
}

From source file:name.martingeisse.common.javascript.JavascriptAssembler.java

License:Open Source License

/**
 * Uses the specified Joda-Time instant and formatter to append a string literal,
 * or the null literal if the argument is null.
 * /*  w w  w.j a va 2 s  .  c o  m*/
 * @param value the instant to append (may be null)
 * @param formatter the formatter used to turn the instant into a string
 * @return this
 */
public final JavascriptAssembler appendJodaLiteralOrNull(ReadableInstant value, DateTimeFormatter formatter) {
    if (value == null) {
        appendNullLiteral();
    } else {
        appendStringLiteral(formatter.print(value));
    }
    return this;
}

From source file:name.martingeisse.common.javascript.JavascriptAssembler.java

License:Open Source License

/**
 * Uses the specified Joda-Time partial and formatter to append a string literal.
 * /* ww w. ja va  2s.c o m*/
 * @param value the partial to append
 * @param formatter the formatter used to turn the partial into a string
 * @return this
 */
public final JavascriptAssembler appendJodaLiteral(ReadablePartial value, DateTimeFormatter formatter) {
    if (value == null) {
        throw new IllegalArgumentException("value argument is null");
    }
    appendStringLiteral(formatter.print(value));
    return this;
}

From source file:name.martingeisse.common.javascript.JavascriptAssembler.java

License:Open Source License

/**
 * Uses the specified Joda-Time partial and formatter to append a string literal,
 * or the null literal if the argument is null.
 * //from ww  w.j  a va  2  s. c o m
 * @param value the partial to append (may be null)
 * @param formatter the formatter used to turn the partial into a string
 * @return this
 */
public final JavascriptAssembler appendJodaLiteralOrNull(ReadablePartial value, DateTimeFormatter formatter) {
    if (value == null) {
        appendNullLiteral();
    } else {
        appendStringLiteral(formatter.print(value));
    }
    return this;
}

From source file:name.martingeisse.sql.config.CustomMysqlDateTimeType.java

License:Open Source License

@Override
protected String print(final DateTimeFormatter formatter, final DateTime value) {
    return formatter.print(value);
}

From source file:name.martingeisse.sql.config.CustomMysqlLocalDateTimeType.java

License:Open Source License

@Override
protected String print(final DateTimeFormatter formatter, final LocalDateTime value) {
    return formatter.print(value);
}

From source file:name.martingeisse.sql.config.CustomMysqlLocalDateType.java

License:Open Source License

@Override
protected String print(final DateTimeFormatter formatter, final LocalDate value) {
    return formatter.print(value);
}

From source file:nc.noumea.mairie.organigramme.core.transformer.MSDateTransformer.java

License:Open Source License

@Override
public void transform(Object arg0) {

    if (arg0 == null) {
        getContext().write(null);/*  ww w.ja  v  a 2 s. co m*/
        return;
    }

    DateTime dt = new DateTime(arg0);

    DateTimeFormatter formater = new DateTimeFormatterBuilder().appendLiteral("/Date(")
            .appendLiteral(String.format("%s", dt.getMillis())).appendPattern("Z").appendLiteral(")/")
            .toFormatter();

    getContext().writeQuoted(formater.print(dt));
}

From source file:nc.noumea.mairie.organigramme.core.utility.JsonDateSerializer.java

License:Open Source License

@Override
public void serialize(Date date, JsonGenerator gen, SerializerProvider provider)
        throws IOException, JsonProcessingException {

    if (date == null) {
        gen.writeNull();//w ww.j  a  v a  2s. c om
        return;
    }

    DateTime dt = new DateTime(date);

    DateTimeFormatter formater = new DateTimeFormatterBuilder().appendLiteral("/Date(")
            .appendLiteral(String.format("%s", dt.getMillis())).appendPattern("Z").appendLiteral(")/")
            .toFormatter();

    gen.writeString(formater.print(dt));
}

From source file:net.asfun.jangod.lib.filter.DatetimeFilter.java

License:Apache License

@Override
public Object filter(Object object, JangodInterpreter interpreter, String... arg) throws InterpretException {
    if (object == null) {
        return object;
    }//www .j  a v a2s .  com
    if (object instanceof DateTime) { // joda DateTime
        DateTimeFormatter formatter;
        DateTimeFormatter a = DateTimeFormat.forPattern(interpreter.evaluateExpressionAsString(arg[0]));
        if (arg.length == 1) {
            DateTimeFormatter forPattern = a;
            JodaTimeContext jodaTimeContext = JodaTimeContextHolder.getJodaTimeContext();
            if (jodaTimeContext == null) {
                jodaTimeContext = new JodaTimeContext();
            }
            formatter = jodaTimeContext.getFormatter(forPattern);
        } else if (arg.length == 2) {
            formatter = a.withChronology(ISOChronology
                    .getInstance(DateTimeZone.forID(interpreter.evaluateExpressionAsString(arg[1]))));
        } else {
            throw new InterpretException("filter date expects 1 or 2 args >>> " + arg.length);
        }
        return formatter.print((DateTime) object);
    } else {
        SimpleDateFormat sdf;
        if (arg.length == 1) {
            sdf = new SimpleDateFormat(interpreter.evaluateExpressionAsString(arg[0]));
            sdf.setTimeZone(interpreter.getConfiguration().getTimezone());
        } else if (arg.length == 2) {
            sdf = new SimpleDateFormat(interpreter.evaluateExpressionAsString(arg[0]));
            sdf.setTimeZone(TimeZone.getTimeZone(interpreter.evaluateExpressionAsString(arg[1])));
        } else {
            throw new InterpretException("filter date expects 1 or 2 args >>> " + arg.length);
        }
        return sdf.format(object);
    }
}