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

The following examples show how to use org.joda.time.format.ISODateTimeFormat#time() . 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: AmforeasUtils.java    From amforeas with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check if a string has the ISO time format. Uses the ISODateTimeFormat.time() from JodaTime
 * and returns a DateTime instance. The correct format is HH:mm:ss.SSSZZ or HHmmss.SSSZ
 * @param arg the string to check
 * @return a DateTime instance if the string is in the correct ISO format.
 */
public static DateTime isTime (final String arg) {
    if (arg == null)
        return null;
    DateTime ret = null;
    DateTimeFormatter df;
    if (arg.contains(":")) {
        df = ISODateTimeFormat.time();
    } else {
        df = ISODateTimeFormat.basicTime();
    }

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

    return ret;
}
 
Example 2
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 3
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 4
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 5
Source File: VectorOutput.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void writeTime(boolean isNull) throws IOException {
  TimeMilliWriter t = writer.timeMilli();
  if(!isNull){
    DateTimeFormatter f = ISODateTimeFormat.time();
    t.writeTimeMilli((int) com.dremio.common.util.DateTimes.toMillis(f.parseLocalDateTime(parser.getValueAsString())));
  }
}
 
Example 6
Source File: VectorOutput.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void writeTime(boolean isNull) throws IOException {
  TimeMilliWriter t = writer.timeMilli(fieldName);
  if(!isNull){
    DateTimeFormatter f = ISODateTimeFormat.time();
    t.writeTimeMilli((int) com.dremio.common.util.DateTimes.toMillis(f.parseLocalDateTime(parser.getValueAsString())));
  }
}
 
Example 7
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 8
Source File: UtilsTest.java    From amforeas with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testIsTime () {
    DateTimeFormatter df = ISODateTimeFormat.time();
    DateTime date = df.parseDateTime("12:35:45.000Z");
    assertEquals(date, AmforeasUtils.isTime("12:35:45.000Z"));
    assertEquals(date, AmforeasUtils.isTime("123545.000Z"));
    assertNull(AmforeasUtils.isTime(""));
    assertNull(AmforeasUtils.isTime(null));
    assertNull(AmforeasUtils.isTime("2011-01-19"));
    assertNull(AmforeasUtils.isTime("20110119"));
    assertNull(AmforeasUtils.isTime("22:00:00"));
    assertNull(AmforeasUtils.isTime("2011-12-11T12:35:45.200Z"));
}
 
Example 9
Source File: ConvertTimeToString.java    From Bats with Apache License 2.0 4 votes vote down vote up
public ConvertTimeToString(ScalarWriter baseWriter) {
  super(baseWriter);
  final String formatValue = baseWriter.schema().format();
  dateTimeFormatter = formatValue == null
    ? ISODateTimeFormat.time() : DateTimeFormat.forPattern(formatValue);
}