Java Code Examples for org.joda.time.format.ISODateTimeFormat#date()

The following examples show how to use org.joda.time.format.ISODateTimeFormat#date() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Serializer.java    From omise-java with MIT License 8 votes vote down vote up
private Serializer() {
    dateTimeFormatter = ISODateTimeFormat.dateTimeNoMillis();
    localDateFormatter = ISODateTimeFormat.date();

    objectMapper = new ObjectMapper()
            .registerModule(new JodaModule()
                    .addSerializer(DateTime.class, new DateTimeSerializer()
                            .withFormat(new JacksonJodaDateFormat(dateTimeFormatter), 0)
                    )
                    .addSerializer(LocalDate.class, new LocalDateSerializer()
                            .withFormat(new JacksonJodaDateFormat(localDateFormatter), 0)
                    )
            )

            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            .configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE, true)
            .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
            .configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); // TODO: Deprecate in vNext
}
 
Example 2
Source File: Time_18_GJChronology_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Gets a debugging toString.
 * 
 * @return a debugging string
 */
public String toString() {
    StringBuffer sb = new StringBuffer(60);
    sb.append("GJChronology");
    sb.append('[');
    sb.append(getZone().getID());
    
    if (iCutoverMillis != DEFAULT_CUTOVER.getMillis()) {
        sb.append(",cutover=");
        DateTimeFormatter printer;
        if (withUTC().dayOfYear().remainder(iCutoverMillis) == 0) {
            printer = ISODateTimeFormat.date();
        } else {
            printer = ISODateTimeFormat.dateTime();
        }
        printer.withChronology(withUTC()).printTo(sb, iCutoverMillis);
    }
    
    if (getMinimumDaysInFirstWeek() != 4) {
        sb.append(",mdfw=");
        sb.append(getMinimumDaysInFirstWeek());
    }
    sb.append(']');
    
    return sb.toString();
}
 
Example 3
Source File: AmforeasUtils.java    From amforeas with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check if a string has the ISO date format. Uses the ISODateTimeFormat.date() from JodaTime
 * and returns a DateTime instance. The correct format is yyyy-MM-dd or yyyyMMdd
 * @param arg the string to check
 * @return a DateTime instance if the string is in the correct ISO format.
 */
public static DateTime isDate (final String arg) {
    if (arg == null)
        return null;
    DateTime ret = null;
    DateTimeFormatter df;
    if (arg.contains("-")) {
        df = ISODateTimeFormat.date();
    } else {
        df = ISODateTimeFormat.basicDate();
    }

    try {
        ret = df.parseDateTime(arg);
    } catch (IllegalArgumentException e) {
        l.debug("{} is not a valid ISO date", arg);
    }

    return ret;
}
 
Example 4
Source File: BoundaryDate.java    From DataGenerator with Apache License 2.0 6 votes vote down vote up
/**
 * Grab random holiday from the equivalence class that falls between the two dates
 *
 * @param earliest the earliest date parameter as defined in the model
 * @param latest   the latest date parameter as defined in the model
 * @return a holiday that falls between the dates
 */
public String getRandomHoliday(String earliest, String latest) {
    String dateString = "";
    DateTimeFormatter parser = ISODateTimeFormat.date();
    DateTime earlyDate = parser.parseDateTime(earliest);
    DateTime lateDate = parser.parseDateTime(latest);
    List<Holiday> holidays = new LinkedList<>();

    int min = Integer.parseInt(earlyDate.toString().substring(0, 4));
    int max = Integer.parseInt(lateDate.toString().substring(0, 4));
    int range = max - min + 1;
    int randomYear = (int) (Math.random() * range) + min;

    for (Holiday s : EquivalenceClassTransformer.HOLIDAYS) {
        holidays.add(s);
    }
    Collections.shuffle(holidays);

    for (Holiday holiday : holidays) {
        dateString = convertToReadableDate(holiday.forYear(randomYear));
        if (toDate(dateString).after(toDate(earliest)) && toDate(dateString).before(toDate(latest))) {
            break;
        }
    }
    return dateString;
}
 
Example 5
Source File: BoundaryDate.java    From DataGenerator with Apache License 2.0 6 votes vote down vote up
/**
 * @param isNullable isNullable
 * @param earliest   lower boundary date
 * @param latest     upper boundary date
 * @return a list of boundary dates
 */
public List<String> negativeCase(boolean isNullable, String earliest, String latest) {
    List<String> values = new LinkedList<>();

    DateTimeFormatter parser = ISODateTimeFormat.date();
    DateTime earlyDate = parser.parseDateTime(earliest);
    DateTime lateDate = parser.parseDateTime(latest);

    String prevDay = parser.print(earlyDate.minusDays(1));
    String nextDay = parser.print(lateDate.plusDays(1));

    values.add(prevDay);
    values.add(nextDay);
    values.add(nextDay.substring(5, 7) + "-" + nextDay.substring(8, 10) + "-" + nextDay.substring(0, 4));
    values.add(getRandomHoliday(earliest, latest));

    if (!isNullable) {
        values.add("");
    }
    return values;
}
 
Example 6
Source File: GJChronology.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Gets a debugging toString.
 * 
 * @return a debugging string
 */
public String toString() {
    StringBuffer sb = new StringBuffer(60);
    sb.append("GJChronology");
    sb.append('[');
    sb.append(getZone().getID());
    
    if (iCutoverMillis != DEFAULT_CUTOVER.getMillis()) {
        sb.append(",cutover=");
        DateTimeFormatter printer;
        if (withUTC().dayOfYear().remainder(iCutoverMillis) == 0) {
            printer = ISODateTimeFormat.date();
        } else {
            printer = ISODateTimeFormat.dateTime();
        }
        printer.withChronology(withUTC()).printTo(sb, iCutoverMillis);
    }
    
    if (getMinimumDaysInFirstWeek() != 4) {
        sb.append(",mdfw=");
        sb.append(getMinimumDaysInFirstWeek());
    }
    sb.append(']');
    
    return sb.toString();
}
 
Example 7
Source File: GJChronology.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Gets a debugging toString.
 * 
 * @return a debugging string
 */
public String toString() {
    StringBuffer sb = new StringBuffer(60);
    sb.append("GJChronology");
    sb.append('[');
    sb.append(getZone().getID());
    
    if (iCutoverMillis != DEFAULT_CUTOVER.getMillis()) {
        sb.append(",cutover=");
        DateTimeFormatter printer;
        if (withUTC().dayOfYear().remainder(iCutoverMillis) == 0) {
            printer = ISODateTimeFormat.date();
        } else {
            printer = ISODateTimeFormat.dateTime();
        }
        printer.withChronology(withUTC()).printTo(sb, iCutoverMillis);
    }
    
    if (getMinimumDaysInFirstWeek() != 4) {
        sb.append(",mdfw=");
        sb.append(getMinimumDaysInFirstWeek());
    }
    sb.append(']');
    
    return sb.toString();
}
 
Example 8
Source File: Time_6_GJChronology_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Gets a debugging toString.
 * 
 * @return a debugging string
 */
public String toString() {
    StringBuffer sb = new StringBuffer(60);
    sb.append("GJChronology");
    sb.append('[');
    sb.append(getZone().getID());
    
    if (iCutoverMillis != DEFAULT_CUTOVER.getMillis()) {
        sb.append(",cutover=");
        DateTimeFormatter printer;
        if (withUTC().dayOfYear().remainder(iCutoverMillis) == 0) {
            printer = ISODateTimeFormat.date();
        } else {
            printer = ISODateTimeFormat.dateTime();
        }
        printer.withChronology(withUTC()).printTo(sb, iCutoverMillis);
    }
    
    if (getMinimumDaysInFirstWeek() != 4) {
        sb.append(",mdfw=");
        sb.append(getMinimumDaysInFirstWeek());
    }
    sb.append(']');
    
    return sb.toString();
}
 
Example 9
Source File: Time_6_GJChronology_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Gets a debugging toString.
 * 
 * @return a debugging string
 */
public String toString() {
    StringBuffer sb = new StringBuffer(60);
    sb.append("GJChronology");
    sb.append('[');
    sb.append(getZone().getID());
    
    if (iCutoverMillis != DEFAULT_CUTOVER.getMillis()) {
        sb.append(",cutover=");
        DateTimeFormatter printer;
        if (withUTC().dayOfYear().remainder(iCutoverMillis) == 0) {
            printer = ISODateTimeFormat.date();
        } else {
            printer = ISODateTimeFormat.dateTime();
        }
        printer.withChronology(withUTC()).printTo(sb, iCutoverMillis);
    }
    
    if (getMinimumDaysInFirstWeek() != 4) {
        sb.append(",mdfw=");
        sb.append(getMinimumDaysInFirstWeek());
    }
    sb.append(']');
    
    return sb.toString();
}
 
Example 10
Source File: Time_18_GJChronology_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Gets a debugging toString.
 * 
 * @return a debugging string
 */
public String toString() {
    StringBuffer sb = new StringBuffer(60);
    sb.append("GJChronology");
    sb.append('[');
    sb.append(getZone().getID());
    
    if (iCutoverMillis != DEFAULT_CUTOVER.getMillis()) {
        sb.append(",cutover=");
        DateTimeFormatter printer;
        if (withUTC().dayOfYear().remainder(iCutoverMillis) == 0) {
            printer = ISODateTimeFormat.date();
        } else {
            printer = ISODateTimeFormat.dateTime();
        }
        printer.withChronology(withUTC()).printTo(sb, iCutoverMillis);
    }
    
    if (getMinimumDaysInFirstWeek() != 4) {
        sb.append(",mdfw=");
        sb.append(getMinimumDaysInFirstWeek());
    }
    sb.append(']');
    
    return sb.toString();
}
 
Example 11
Source File: DateTimeFormatterFactory.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new {@code DateTimeFormatter} using this factory.
 * <p>If no specific pattern or style has been defined,
 * the supplied {@code fallbackFormatter} will be used.
 * @param fallbackFormatter the fall-back formatter to use when no specific
 * factory properties have been set (can be {@code null}).
 * @return a new date time formatter
 */
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
	DateTimeFormatter dateTimeFormatter = null;
	if (StringUtils.hasLength(this.pattern)) {
		dateTimeFormatter = DateTimeFormat.forPattern(this.pattern);
	}
	else if (this.iso != null && this.iso != ISO.NONE) {
		switch (this.iso) {
			case DATE:
				dateTimeFormatter = ISODateTimeFormat.date();
				break;
			case TIME:
				dateTimeFormatter = ISODateTimeFormat.time();
				break;
			case DATE_TIME:
				dateTimeFormatter = ISODateTimeFormat.dateTime();
				break;
			case NONE:
				/* no-op */
				break;
			default:
				throw new IllegalStateException("Unsupported ISO format: " + this.iso);
		}
	}
	else if (StringUtils.hasLength(this.style)) {
		dateTimeFormatter = DateTimeFormat.forStyle(this.style);
	}

	if (dateTimeFormatter != null && this.timeZone != null) {
		dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone));
	}
	return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}
 
Example 12
Source File: DateTimeFormatterFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new {@code DateTimeFormatter} using this factory.
 * <p>If no specific pattern or style has been defined,
 * the supplied {@code fallbackFormatter} will be used.
 * @param fallbackFormatter the fall-back formatter to use when no specific
 * factory properties have been set (can be {@code null}).
 * @return a new date time formatter
 */
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
	DateTimeFormatter dateTimeFormatter = null;
	if (StringUtils.hasLength(this.pattern)) {
		dateTimeFormatter = DateTimeFormat.forPattern(this.pattern);
	}
	else if (this.iso != null && this.iso != ISO.NONE) {
		switch (this.iso) {
			case DATE:
				dateTimeFormatter = ISODateTimeFormat.date();
				break;
			case TIME:
				dateTimeFormatter = ISODateTimeFormat.time();
				break;
			case DATE_TIME:
				dateTimeFormatter = ISODateTimeFormat.dateTime();
				break;
			case NONE:
				/* no-op */
				break;
			default:
				throw new IllegalStateException("Unsupported ISO format: " + this.iso);
		}
	}
	else if (StringUtils.hasLength(this.style)) {
		dateTimeFormatter = DateTimeFormat.forStyle(this.style);
	}

	if (dateTimeFormatter != null && this.timeZone != null) {
		dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone));
	}
	return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}
 
Example 13
Source File: BoundaryDate.java    From DataGenerator with Apache License 2.0 5 votes vote down vote up
/**
 * @param isNullable isNullable
 * @param earliest   lower boundary date
 * @param latest     upper boundary date
 * @param onlyBusinessDays only business days
 * @return a list of boundary dates
 */
public List<String> positiveCase(boolean isNullable, String earliest, String latest, boolean onlyBusinessDays) {
    List<String> values = new LinkedList<>();

    if (earliest.equalsIgnoreCase(latest)) {
        values.add(earliest);
        if (isNullable) {
            values.add("");
        }
        return values;
    }

    DateTimeFormatter parser = ISODateTimeFormat.date();
    DateTime earlyDate = parser.parseDateTime(earliest);
    DateTime lateDate = parser.parseDateTime(latest);

    String earlyDay = parser.print(earlyDate);
    String nextDay = getNextDay(earlyDate.toString().substring(0, 10), onlyBusinessDays);
    String prevDay = getPreviousDay(lateDate.toString().substring(0, 10), onlyBusinessDays);
    String lateDay = parser.print(lateDate);

    values.add(earlyDay);
    values.add(nextDay);
    values.add(prevDay);
    values.add(lateDay);

    if (isNullable) {
        values.add("");
    }
    return values;
}
 
Example 14
Source File: DateTimeFormatterFactory.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create a new {@code DateTimeFormatter} using this factory.
 * <p>If no specific pattern or style has been defined,
 * the supplied {@code fallbackFormatter} will be used.
 * @param fallbackFormatter the fall-back formatter to use
 * when no specific factory properties have been set
 * @return a new date time formatter
 */
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
	DateTimeFormatter dateTimeFormatter = null;
	if (StringUtils.hasLength(this.pattern)) {
		dateTimeFormatter = DateTimeFormat.forPattern(this.pattern);
	}
	else if (this.iso != null && this.iso != ISO.NONE) {
		switch (this.iso) {
			case DATE:
				dateTimeFormatter = ISODateTimeFormat.date();
				break;
			case TIME:
				dateTimeFormatter = ISODateTimeFormat.time();
				break;
			case DATE_TIME:
				dateTimeFormatter = ISODateTimeFormat.dateTime();
				break;
			default:
				throw new IllegalStateException("Unsupported ISO format: " + this.iso);
		}
	}
	else if (StringUtils.hasLength(this.style)) {
		dateTimeFormatter = DateTimeFormat.forStyle(this.style);
	}

	if (dateTimeFormatter != null && this.timeZone != null) {
		dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone));
	}
	return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}
 
Example 15
Source File: DateTimeFormatterFactory.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create a new {@code DateTimeFormatter} using this factory.
 * <p>If no specific pattern or style has been defined,
 * the supplied {@code fallbackFormatter} will be used.
 * @param fallbackFormatter the fall-back formatter to use
 * when no specific factory properties have been set
 * @return a new date time formatter
 */
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
	DateTimeFormatter dateTimeFormatter = null;
	if (StringUtils.hasLength(this.pattern)) {
		dateTimeFormatter = DateTimeFormat.forPattern(this.pattern);
	}
	else if (this.iso != null && this.iso != ISO.NONE) {
		switch (this.iso) {
			case DATE:
				dateTimeFormatter = ISODateTimeFormat.date();
				break;
			case TIME:
				dateTimeFormatter = ISODateTimeFormat.time();
				break;
			case DATE_TIME:
				dateTimeFormatter = ISODateTimeFormat.dateTime();
				break;
			default:
				throw new IllegalStateException("Unsupported ISO format: " + this.iso);
		}
	}
	else if (StringUtils.hasLength(this.style)) {
		dateTimeFormatter = DateTimeFormat.forStyle(this.style);
	}

	if (dateTimeFormatter != null && this.timeZone != null) {
		dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone));
	}
	return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}
 
Example 16
Source File: ConvertDateToString.java    From Bats with Apache License 2.0 4 votes vote down vote up
public ConvertDateToString(ScalarWriter baseWriter) {
  super(baseWriter);
  final String formatValue = baseWriter.schema().format();
  dateTimeFormatter = formatValue == null
    ? ISODateTimeFormat.date() : DateTimeFormat.forPattern(formatValue);
}
 
Example 17
Source File: JSON.java    From director-sdk with Apache License 2.0 4 votes vote down vote up
public LocalDateTypeAdapter() {
    this(ISODateTimeFormat.date());
}
 
Example 18
Source File: RedmineConstants.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
public static final DateTimeFormatter getDateFormatter(boolean alternativeDateFormat) {
	if ( !alternativeDateFormat ) 
		return ISODateTimeFormat.dateTimeNoMillis().withZoneUTC();
	else
		return ISODateTimeFormat.date();
}
 
Example 19
Source File: JSON.java    From java with Apache License 2.0 4 votes vote down vote up
public LocalDateTypeAdapter() {
    this(ISODateTimeFormat.date());
}