Java Code Examples for java.time.OffsetTime#parse()

The following examples show how to use java.time.OffsetTime#parse() . 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: TextParser.java    From pgadba with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Converts the string from the database to an array of OffsetTime objects.
 * @param in the array as a string
 * @param requestedClass the class that the user wanted
 * @return an array of OffsetTime objects
 */
public static Object timetzOutArray(String in, Class<?> requestedClass) {
  if ("{}".equals(in)) {
    return new OffsetTime[] {};
  }

  String[] parts = in.substring(1, in.length() - 1).split(",");

  OffsetTime[] result = new OffsetTime[parts.length];

  for (int i = 0; i < parts.length; i++) {
    if ("NULL".equals(parts[i])) {
      result[i] = null;
    } else {
      result[i] = OffsetTime.parse(parts[i], offsetTimeFormatter);
    }
  }

  return result;
}
 
Example 2
Source File: TCKOffsetTime.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "sampleBadParse", expectedExceptions={DateTimeParseException.class})
public void factory_parse_invalidText(String unparsable) {
    OffsetTime.parse(unparsable);
}
 
Example 3
Source File: TCKOffsetTime.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "sampleBadParse", expectedExceptions={DateTimeParseException.class})
public void factory_parse_invalidText(String unparsable) {
    OffsetTime.parse(unparsable);
}
 
Example 4
Source File: TCKOffsetTime.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "sampleToString")
public void factory_parse_validText(int h, int m, int s, int n, String offsetId, String parsable) {
    OffsetTime t = OffsetTime.parse(parsable);
    assertNotNull(t, parsable);
    check(t, h, m, s, n, ZoneOffset.of(offsetId));
}
 
Example 5
Source File: TCKOffsetTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions={DateTimeParseException.class})
public void factory_parse_illegalSecond() {
    OffsetTime.parse("12:12:60+01:00");
}
 
Example 6
Source File: TCKOffsetTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullFormatter() {
    OffsetTime.parse("ANY", null);
}
 
Example 7
Source File: TCKOffsetTime.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullText() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
    OffsetTime.parse((String) null, f);
}
 
Example 8
Source File: ConverterTest.java    From microprofile-config with Apache License 2.0 4 votes vote down vote up
@Test
public void testOffsetTime() {
    OffsetTime value = config.getValue("tck.config.test.javaconfig.converter.offsettimevalue", OffsetTime.class);
    OffsetTime parsed = OffsetTime.parse("13:45:30.123456789+02:00");
    Assert.assertEquals(value, parsed);
}
 
Example 9
Source File: TCKOffsetTime.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factory_parse_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("H m s XXX");
    OffsetTime test = OffsetTime.parse("11 30 0 +01:00", f);
    assertEquals(test, OffsetTime.of(11, 30, 0, 0, ZoneOffset.ofHours(1)));
}
 
Example 10
Source File: OffsetTimeEncoding.java    From ndbc with Apache License 2.0 4 votes vote down vote up
@Override
public final OffsetTime decodeText(final String value) {
  return OffsetTime.parse(value, formatter);
}
 
Example 11
Source File: TCKOffsetTime.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions={DateTimeParseException.class})
public void factory_parse_illegalMinute() {
    OffsetTime.parse("12:60+01:00");
}
 
Example 12
Source File: TCKOffsetTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullFormatter() {
    OffsetTime.parse("ANY", null);
}
 
Example 13
Source File: TCKOffsetTime.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=DateTimeParseException.class)
public void factory_parse_illegalMinute() {
    OffsetTime.parse("12:60+01:00");
}
 
Example 14
Source File: TCKOffsetTime.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions={DateTimeParseException.class})
public void factory_parse_illegalHour() {
    OffsetTime.parse("25:00+01:00");
}
 
Example 15
Source File: TCKOffsetTime.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factory_parse_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("H m s XXX");
    OffsetTime test = OffsetTime.parse("11 30 0 +01:00", f);
    assertEquals(test, OffsetTime.of(11, 30, 0, 0, ZoneOffset.ofHours(1)));
}
 
Example 16
Source File: TCKOffsetTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions={DateTimeParseException.class})
public void factory_parse_illegalHour() {
    OffsetTime.parse("25:00+01:00");
}
 
Example 17
Source File: TCKOffsetTime.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=NullPointerException.class)
public void factory_parse_formatter_nullText() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
    OffsetTime.parse((String) null, f);
}
 
Example 18
Source File: TCKOffsetTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "sampleBadParse", expectedExceptions={DateTimeParseException.class})
public void factory_parse_invalidText(String unparsable) {
    OffsetTime.parse(unparsable);
}
 
Example 19
Source File: TCKOffsetTime.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions={DateTimeParseException.class})
public void factory_parse_illegalMinute() {
    OffsetTime.parse("12:60+01:00");
}
 
Example 20
Source File: ConverterTest.java    From microprofile-config with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetOffsetTimeConverter() {
    OffsetTime value = config.getConverter(OffsetTime.class).get().convert("13:45:30.123456789+02:00");
    OffsetTime parsed = OffsetTime.parse("13:45:30.123456789+02:00");
    Assert.assertEquals(value, parsed);
}