Search in sources :

Example 6 with FastDateFormat

use of org.apache.commons.lang3.time.FastDateFormat in project pact-jvm by DiUS.

the class PactDslJsonBody method date.

/**
     * Attribute that must match the provided date format
     * @param name attribute date
     * @param format date format to match
     * @param example example date to use for generated values
     */
public PactDslJsonBody date(String name, String format, Date example) {
    FastDateFormat instance = FastDateFormat.getInstance(format);
    body.put(name, instance.format(example));
    matchers.put(matcherKey(name), matchDate(format));
    return this;
}
Also used : FastDateFormat(org.apache.commons.lang3.time.FastDateFormat)

Example 7 with FastDateFormat

use of org.apache.commons.lang3.time.FastDateFormat in project pact-jvm by DiUS.

the class PactDslJsonBody method timestamp.

/**
     * Attribute that must match the given timestamp format
     * @param name attribute name
     * @param format timestamp format
     */
public PactDslJsonBody timestamp(String name, String format) {
    FastDateFormat instance = FastDateFormat.getInstance(format);
    body.put(name, instance.format(new Date()));
    matchers.put(matcherKey(name), matchTimestamp(format));
    return this;
}
Also used : FastDateFormat(org.apache.commons.lang3.time.FastDateFormat) Date(java.util.Date)

Example 8 with FastDateFormat

use of org.apache.commons.lang3.time.FastDateFormat in project pact-jvm by DiUS.

the class PactDslJsonRootValue method date.

/**
   * Value that must match the provided date format
   * @param format date format to match
   * @param example example date to use for generated values
   */
public static PactDslJsonRootValue date(String format, Date example) {
    FastDateFormat instance = FastDateFormat.getInstance(format);
    PactDslJsonRootValue value = new PactDslJsonRootValue();
    value.setValue(instance.format(example));
    value.setMatcher(value.matchDate(format));
    return value;
}
Also used : FastDateFormat(org.apache.commons.lang3.time.FastDateFormat)

Example 9 with FastDateFormat

use of org.apache.commons.lang3.time.FastDateFormat in project pact-jvm by DiUS.

the class PactDslJsonRootValue method time.

/**
   * Value that must match the given time format
   * @param format time format to match
   * @param example example time to use for generated bodies
   */
public static PactDslJsonRootValue time(String format, Date example) {
    FastDateFormat instance = FastDateFormat.getInstance(format);
    PactDslJsonRootValue value = new PactDslJsonRootValue();
    value.setValue(instance.format(example));
    value.setMatcher(value.matchTime(format));
    return value;
}
Also used : FastDateFormat(org.apache.commons.lang3.time.FastDateFormat)

Example 10 with FastDateFormat

use of org.apache.commons.lang3.time.FastDateFormat in project Klyph by jonathangerbaud.

the class DateUtil method getShortDate.

public static String getShortDate(String unixDate) {
    Date date = new Date(Long.parseLong(unixDate) * 1000);
    Date now = new Date();
    String pattern = "";
    // If date < 7 days
    if (now.getTime() - date.getTime() < 7 * 24 * 60 * 60 * 1000) {
        pattern = "E";
    } else {
        FastDateFormat dateFormat = FastDateFormat.getDateInstance(FastDateFormat.MEDIUM);
        pattern = dateFormat.getPattern();
        pattern = pattern.replace("y", "");
        // y in chinese
        pattern = pattern.replace("年", "");
        pattern = pattern.replace(",", "");
        pattern = pattern.replace("  ", " ");
        pattern = pattern.trim();
        if (pattern.indexOf("/") == 0 || pattern.indexOf("-") == 0 || pattern.indexOf(".") == 0) {
            pattern = pattern.substring(1);
        }
    }
    FastDateFormat dateFormat = FastDateFormat.getInstance(pattern);
    return dateFormat.format(date);
}
Also used : FastDateFormat(org.apache.commons.lang3.time.FastDateFormat) Date(java.util.Date)

Aggregations

FastDateFormat (org.apache.commons.lang3.time.FastDateFormat)17 Date (java.util.Date)8 Calendar (java.util.Calendar)1