Search in sources :

Example 11 with FastDateFormat

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

the class DateUtil method getShortDateTime.

public static String getShortDateTime(String unixDate) {
    Date date = new Date(Long.parseLong(unixDate) * 1000);
    Calendar c1 = CALENDAR;
    c1.setTime(new Date());
    Calendar c2 = Calendar.getInstance();
    c2.setTime(date);
    FastDateFormat dateFormat = FastDateFormat.getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.SHORT);
    String pattern = dateFormat.getPattern();
    // If not same year
    if (c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR)) {
        pattern = pattern.replace("y", "");
        if (pattern.indexOf("/") == 0 || pattern.indexOf("-") == 0 || pattern.indexOf(".") == 0 || pattern.indexOf("年") == 0) {
            pattern = pattern.substring(1);
        }
    /*			pattern = pattern.replace("EEEE", "EEE");
			pattern = pattern.replace("MMMM", "");
			pattern = pattern.replace("d", "");
		}
		else
		{
			pattern = pattern.replace("MMMM", "MMM");
			pattern = pattern.replace("EEEE", "");*/
    }
    pattern = pattern.replace("  ", " ");
    pattern = pattern.trim();
    dateFormat = FastDateFormat.getInstance(pattern);
    return dateFormat.format(date);
}
Also used : Calendar(java.util.Calendar) FastDateFormat(org.apache.commons.lang3.time.FastDateFormat) Date(java.util.Date)

Example 12 with FastDateFormat

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

the class PactDslJsonBody method time.

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

Example 13 with FastDateFormat

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

the class PactDslJsonRootValue method timestamp.

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

Example 14 with FastDateFormat

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

the class PactDslJsonArray method date.

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

Example 15 with FastDateFormat

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

the class PactDslJsonArray method timestamp.

/**
     * Element that must match the given timestamp format
     * @param format timestamp format
     * @param example example date and time to use for generated bodies
     */
public PactDslJsonArray timestamp(String format, Date example) {
    FastDateFormat instance = FastDateFormat.getInstance(format);
    body.put(instance.format(example));
    matchers.put(rootPath + appendArrayIndex(0), matchTimestamp(format));
    return this;
}
Also used : FastDateFormat(org.apache.commons.lang3.time.FastDateFormat)

Aggregations

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