Java Code Examples for org.joda.time.LocalTime#parse()

The following examples show how to use org.joda.time.LocalTime#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: TestDataGenerator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public static User generateRandomUser(Random rnd) {
	return new User(
			generateRandomString(rnd, 50),
			rnd.nextBoolean() ? null : rnd.nextInt(),
			rnd.nextBoolean() ? null : generateRandomString(rnd, 6),
			rnd.nextBoolean() ? null : rnd.nextLong(),
			rnd.nextDouble(),
			null,
			rnd.nextBoolean(),
			generateRandomStringList(rnd, 20, 30),
			generateRandomBooleanList(rnd, 20),
			rnd.nextBoolean() ? null : generateRandomStringList(rnd, 20, 20),
			generateRandomColor(rnd),
			new HashMap<>(),
			generateRandomFixed16(rnd),
			generateRandomUnion(rnd),
			generateRandomAddress(rnd),
			generateRandomBytes(rnd),
			LocalDate.parse("2014-03-01"),
			LocalTime.parse("12:12:12"),
			123456,
			DateTime.parse("2014-03-01T12:12:12.321Z"),
			123456L,
			ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()),
			new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
}
 
Example 2
Source File: TestDataGenerator.java    From flink with Apache License 2.0 6 votes vote down vote up
public static User generateRandomUser(Random rnd) {
	return new User(
			generateRandomString(rnd, 50),
			rnd.nextBoolean() ? null : rnd.nextInt(),
			rnd.nextBoolean() ? null : generateRandomString(rnd, 6),
			rnd.nextBoolean() ? null : rnd.nextLong(),
			rnd.nextDouble(),
			null,
			rnd.nextBoolean(),
			generateRandomStringList(rnd, 20, 30),
			generateRandomBooleanList(rnd, 20),
			rnd.nextBoolean() ? null : generateRandomStringList(rnd, 20, 20),
			generateRandomColor(rnd),
			new HashMap<>(),
			generateRandomFixed16(rnd),
			generateRandomUnion(rnd),
			generateRandomAddress(rnd),
			generateRandomBytes(rnd),
			LocalDate.parse("2014-03-01"),
			LocalTime.parse("12:12:12"),
			123456,
			DateTime.parse("2014-03-01T12:12:12.321Z"),
			123456L,
			ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()),
			new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
}
 
Example 3
Source File: TestDataGenerator.java    From flink with Apache License 2.0 6 votes vote down vote up
public static User generateRandomUser(Random rnd) {
	return new User(
			generateRandomString(rnd, 50),
			rnd.nextBoolean() ? null : rnd.nextInt(),
			rnd.nextBoolean() ? null : generateRandomString(rnd, 6),
			rnd.nextBoolean() ? null : rnd.nextLong(),
			rnd.nextDouble(),
			null,
			rnd.nextBoolean(),
			generateRandomStringList(rnd, 20, 30),
			generateRandomBooleanList(rnd, 20),
			rnd.nextBoolean() ? null : generateRandomStringList(rnd, 20, 20),
			generateRandomColor(rnd),
			new HashMap<>(),
			generateRandomFixed16(rnd),
			generateRandomUnion(rnd),
			generateRandomAddress(rnd),
			generateRandomBytes(rnd),
			LocalDate.parse("2014-03-01"),
			LocalTime.parse("12:12:12"),
			123456,
			DateTime.parse("2014-03-01T12:12:12.321Z"),
			123456L,
			ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()),
			new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
}
 
Example 4
Source File: QiblaTimeView.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    removeCallbacks(this);
    mPrayTimes.setCoordinates(mLat, mLng, mAlt);
    mQiblaTime = mPrayTimes.getQiblaTime();
    LocalTime sunrise = LocalTime.parse(mPrayTimes.getTime(Times.Sunrise));
    LocalTime sunset = LocalTime.parse(mPrayTimes.getTime(Times.Sunset));
    LocalTime current = LocalTime.now();

    mShowSun = !(sunset.isBefore(current) || sunrise.isAfter(current));

    mSunriseAngle = Math.toDegrees(getAzimuth(sunrise.toDateTimeToday().getMillis(), mLat, mLng)) - mQiblaAngle - 90;
    mSunsetAngle = Math.toDegrees(getAzimuth(sunset.toDateTimeToday().getMillis(), mLat, mLng)) - mQiblaAngle - 90;
    mCurrentAngle = Math.toDegrees(getAzimuth(current.toDateTimeToday().getMillis(), mLat, mLng)) - mQiblaAngle - 90;

    while (mSunriseAngle < 0) mSunriseAngle += 360;
    while (mSunsetAngle < 0) mSunsetAngle += 360;
    while (mSunriseAngle >= 360) mSunriseAngle -= 360;
    while (mSunsetAngle >= 360) mSunsetAngle -= 360;
    if (mSunsetAngle > mSunriseAngle) mSunsetAngle -= 360;


    invalidate();
}
 
Example 5
Source File: QiblaTimeView.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    removeCallbacks(this);
    mPrayTimes.setCoordinates(mLat, mLng, mAlt);
    mQiblaTime = mPrayTimes.getQiblaTime();
    LocalTime sunrise = LocalTime.parse(mPrayTimes.getTime(Times.Sunrise));
    LocalTime sunset = LocalTime.parse(mPrayTimes.getTime(Times.Sunset));
    LocalTime current = LocalTime.now();

    mShowSun = !(sunset.isBefore(current) || sunrise.isAfter(current));

    mSunriseAngle = Math.toDegrees(getAzimuth(sunrise.toDateTimeToday().getMillis(), mLat, mLng)) - mQiblaAngle - 90;
    mSunsetAngle = Math.toDegrees(getAzimuth(sunset.toDateTimeToday().getMillis(), mLat, mLng)) - mQiblaAngle - 90;
    mCurrentAngle = Math.toDegrees(getAzimuth(current.toDateTimeToday().getMillis(), mLat, mLng)) - mQiblaAngle - 90;

    while (mSunriseAngle < 0) mSunriseAngle += 360;
    while (mSunsetAngle < 0) mSunsetAngle += 360;
    while (mSunriseAngle >= 360) mSunriseAngle -= 360;
    while (mSunsetAngle >= 360) mSunsetAngle -= 360;
    if (mSunsetAngle > mSunriseAngle) mSunsetAngle -= 360;


    invalidate();
}
 
Example 6
Source File: OTime.java    From ojai with Apache License 2.0 5 votes vote down vote up
/**
 * Parses and return an instance of {@code OTime} from the specified string.
 * @param timeStr  the string to parse
 * @exception ParseException if the beginning of the specified string
 *            cannot be parsed.
 */
public static OTime parse(String timeStr) {
  try {
    return new OTime(LocalTime.parse(timeStr));
  } catch (IllegalArgumentException e) {
    throw new ParseException(e);
  }
}
 
Example 7
Source File: EncoderDecoderTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testGeneratedObjectWithNullableFields() {
	List<CharSequence> strings = Arrays.asList(new CharSequence[] { "These", "strings", "should", "be", "recognizable", "as", "a", "meaningful", "sequence" });
	List<Boolean> bools = Arrays.asList(true, true, false, false, true, false, true, true);
	Map<CharSequence, Long> map = new HashMap<>();
	map.put("1", 1L);
	map.put("2", 2L);
	map.put("3", 3L);

	byte[] b = new byte[16];
	new Random().nextBytes(b);
	Fixed16 f = new Fixed16(b);
	Address addr = new Address(239, "6th Main", "Bangalore", "Karnataka", "560075");
	User user = new User(
		"Freudenreich",
		1337,
		"macintosh gray",
		1234567890L,
		3.1415926,
		null,
		true,
		strings,
		bools,
		null,
		Colors.GREEN,
		map,
		f,
		Boolean.TRUE,
		addr,
		ByteBuffer.wrap(b),
		LocalDate.parse("2014-03-01"),
		LocalTime.parse("12:12:12"),
		123456,
		DateTime.parse("2014-03-01T12:12:12.321Z"),
		123456L,
		ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()), // 20.00
		new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray())); // 20.00

	testObjectSerialization(user);
}
 
Example 8
Source File: EncoderDecoderTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testGeneratedObjectWithNullableFields() {
	List<CharSequence> strings = Arrays.asList(new CharSequence[] { "These", "strings", "should", "be", "recognizable", "as", "a", "meaningful", "sequence" });
	List<Boolean> bools = Arrays.asList(true, true, false, false, true, false, true, true);
	Map<CharSequence, Long> map = new HashMap<>();
	map.put("1", 1L);
	map.put("2", 2L);
	map.put("3", 3L);

	byte[] b = new byte[16];
	new Random().nextBytes(b);
	Fixed16 f = new Fixed16(b);
	Address addr = new Address(239, "6th Main", "Bangalore", "Karnataka", "560075");
	User user = new User(
		"Freudenreich",
		1337,
		"macintosh gray",
		1234567890L,
		3.1415926,
		null,
		true,
		strings,
		bools,
		null,
		Colors.GREEN,
		map,
		f,
		Boolean.TRUE,
		addr,
		ByteBuffer.wrap(b),
		LocalDate.parse("2014-03-01"),
		LocalTime.parse("12:12:12"),
		123456,
		DateTime.parse("2014-03-01T12:12:12.321Z"),
		123456L,
		ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()), // 20.00
		new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray())); // 20.00

	testObjectSerialization(user);
}
 
Example 9
Source File: EncoderDecoderTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testGeneratedObjectWithNullableFields() {
	List<CharSequence> strings = Arrays.asList(new CharSequence[] { "These", "strings", "should", "be", "recognizable", "as", "a", "meaningful", "sequence" });
	List<Boolean> bools = Arrays.asList(true, true, false, false, true, false, true, true);
	Map<CharSequence, Long> map = new HashMap<>();
	map.put("1", 1L);
	map.put("2", 2L);
	map.put("3", 3L);

	byte[] b = new byte[16];
	new Random().nextBytes(b);
	Fixed16 f = new Fixed16(b);
	Address addr = new Address(239, "6th Main", "Bangalore", "Karnataka", "560075");
	User user = new User(
		"Freudenreich",
		1337,
		"macintosh gray",
		1234567890L,
		3.1415926,
		null,
		true,
		strings,
		bools,
		null,
		Colors.GREEN,
		map,
		f,
		Boolean.TRUE,
		addr,
		ByteBuffer.wrap(b),
		LocalDate.parse("2014-03-01"),
		LocalTime.parse("12:12:12"),
		123456,
		DateTime.parse("2014-03-01T12:12:12.321Z"),
		123456L,
		ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()), // 20.00
		new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray())); // 20.00

	testObjectSerialization(user);
}
 
Example 10
Source File: TimeConstant.java    From FROST-Server with GNU Lesser General Public License v3.0 4 votes vote down vote up
public TimeConstant(String value) {
    super(LocalTime.parse(value));
}
 
Example 11
Source File: SqoopIDFUtils.java    From sqoop-on-spark with Apache License 2.0 4 votes vote down vote up
public static Object toTime(String csvString, Column column) {
  return LocalTime.parse(removeQuotes(csvString));
}
 
Example 12
Source File: PrimitiveColumnMetadata.java    From Bats with Apache License 2.0 4 votes vote down vote up
/**
 * Converts value in string literal form into Object instance based on {@link MinorType} value.
 * Returns null in case of error during parsing or unsupported type.
 *
 * @param value value in string literal form
 * @return Object instance
 */
@Override
public Object valueFromString(String value) {
  if (value == null) {
    return null;
  }
  try {
    switch (type) {
      case INT:
        return Integer.parseInt(value);
      case BIGINT:
        return Long.parseLong(value);
      case FLOAT4:
        return (double) Float.parseFloat(value);
      case FLOAT8:
        return Double.parseDouble(value);
      case VARDECIMAL:
        return new BigDecimal(value);
      case BIT:
        return BooleanType.fromString(value);
      case VARCHAR:
      case VARBINARY:
        return value;
      case TIME:
        return LocalTime.parse(value, dateTimeFormatter());
      case DATE:
        return LocalDate.parse(value, dateTimeFormatter());
      case TIMESTAMP:
        return Instant.parse(value, dateTimeFormatter());
      case INTERVAL:
      case INTERVALDAY:
      case INTERVALYEAR:
        return Period.parse(value);
      default:
        throw new IllegalArgumentException("Unsupported conversion: " + type.toString());
    }
  } catch (IllegalArgumentException e) {
    logger.warn("Error while parsing type {} default value {}", type, value, e);
    throw new IllegalArgumentException(String.format("The string \"%s\" is not valid for type %s",
        value, type), e);
  }
}
 
Example 13
Source File: CassandraPreparedStatementTest.java    From cassandra-jdbc-driver with Apache License 2.0 4 votes vote down vote up
@Test(groups = {"unit", "server"})
public void testTime() {
    String insertCql = "insert into test_drive.basic_data_type(id_uuid, date_time) values(?, ?)";
    String queryCql = "select date_time from test_drive.basic_data_type where id_uuid = ?";
    UUID id = UUID.randomUUID();
    String time = "13:30:54.234";
    long tl = 48654234000000L;
    LocalTime jlt = LocalTime.parse(time);
    Time t = new Time(jlt.toDateTimeToday().getMillis());

    try {
        // set time by string
        java.sql.PreparedStatement s = conn.prepareStatement(insertCql);
        s.setObject(1, id);
        s.setObject(2, CassandraTestHelper.getInstance().replaceParameter(time, Time.class));
        s.execute();
        s.close();

        s = conn.prepareStatement(queryCql);
        s.setObject(1, id);
        ResultSet rs = s.executeQuery();
        rs.next();
        assertEquals(CassandraTestHelper.getInstance().replaceResult(rs.getString(1), Time.class), time);
        assertEquals(CassandraTestHelper.getInstance().replaceResult(rs.getObject(1), Time.class), tl);
        assertEquals(rs.getTime(1), t);
        rs.close();
        s.close();

        // by long
        s = conn.prepareStatement(insertCql);
        s.setObject(1, id);
        s.setObject(2, CassandraTestHelper.getInstance().replaceParameter(tl, Time.class));
        s.execute();
        s.close();

        s = conn.prepareStatement(queryCql);
        s.setObject(1, id);
        rs = s.executeQuery();
        rs.next();
        assertEquals(CassandraTestHelper.getInstance().replaceResult(rs.getString(1), Time.class), time);
        assertEquals(CassandraTestHelper.getInstance().replaceResult(rs.getObject(1), Time.class), tl);
        assertEquals(rs.getTime(1), t);
        rs.close();
        s.close();

        // by time
        s = conn.prepareStatement(insertCql);
        s.setObject(1, id);
        s.setObject(2, CassandraTestHelper.getInstance().replaceParameter(t, Time.class));
        s.execute();
        s.close();

        s = conn.prepareStatement(queryCql);
        s.setObject(1, id);
        rs = s.executeQuery();
        rs.next();
        assertEquals(CassandraTestHelper.getInstance().replaceResult(rs.getString(1), Time.class), time);
        assertEquals(CassandraTestHelper.getInstance().replaceResult(rs.getObject(1), Time.class), tl);
        assertEquals(rs.getTime(1), t);
        rs.close();
        s.close();

        // by Joda LocalTime
        s = conn.prepareStatement(insertCql);
        s.setObject(1, id);
        s.setObject(2, CassandraTestHelper.getInstance().replaceParameter(jlt, Time.class));
        s.execute();
        s.close();

        s = conn.prepareStatement(queryCql);
        s.setObject(1, id);
        rs = s.executeQuery();
        rs.next();
        assertEquals(CassandraTestHelper.getInstance().replaceResult(rs.getString(1), Time.class), time);
        assertEquals(CassandraTestHelper.getInstance().replaceResult(rs.getObject(1), Time.class), tl);
        assertEquals(rs.getTime(1), t);
        rs.close();
        s.close();
    } catch (Exception e) {
        e.printStackTrace();
        fail("Error occurred during testing: " + e.getMessage());
    }
}
 
Example 14
Source File: Fixtures.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public static LocalTime time(String str){
  return LocalTime.parse(str);
}
 
Example 15
Source File: TimeDatum.java    From incubator-tajo with Apache License 2.0 4 votes vote down vote up
public TimeDatum(String timeStr) {
  super(TajoDataTypes.Type.TIME);
  time = LocalTime.parse(timeStr, DEFAULT_FORMATTER);
}
 
Example 16
Source File: DatumFactory.java    From incubator-tajo with Apache License 2.0 4 votes vote down vote up
public static TimeDatum createTime(String dateStr) {
  return new TimeDatum(LocalTime.parse(dateStr));
}
 
Example 17
Source File: ParseLocalTime.java    From super-csv with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected LocalTime parse(final String string) {
	return LocalTime.parse(string);
}
 
Example 18
Source File: ParseLocalTime.java    From super-csv with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected LocalTime parse(final String string,
		final DateTimeFormatter formatter) {
	return LocalTime.parse(string, formatter);
}
 
Example 19
Source File: LocalTimeConverter.java    From gson-jodatime-serialisers with MIT License 3 votes vote down vote up
/**
 * Gson invokes this call-back method during deserialization when it encounters a field of the
 * specified type. <p>
 *
 * In the implementation of this call-back method, you should consider invoking
 * {@link JsonDeserializationContext#deserialize(JsonElement, Type)} method to create objects
 * for any non-trivial field of the returned object. However, you should never invoke it on the
 * the same type passing {@code json} since that will cause an infinite loop (Gson will call your
 * call-back method again).
 * @param json The Json data being deserialized
 * @param typeOfT The type of the Object to deserialize to
 * @return a deserialized object of the specified type typeOfT which is a subclass of {@code T}
 * @throws JsonParseException if json is not in the expected format of {@code typeOfT}
 */
@Override
public LocalTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
    throws JsonParseException
{
  // Do not try to deserialize null or empty values
  if (json.getAsString() == null || json.getAsString().isEmpty())
  {
    return null;
  }

  return LocalTime.parse(json.getAsString(), FORMATTER);
}