private SqlTime toTime(LocalTime time) { return sqlTimeOf(time, session); }
public static SqlTime sqlTimeOf( int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond, Session session) { LocalTime time = LocalTime.of(hourOfDay, minuteOfHour, secondOfMinute, millisToNanos(millisOfSecond)); return sqlTimeOf(time, session); }
@Test @Override public void testCastToTime() { assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 +07:09' as time)", TIME, sqlTimeOf(2 /* not 3 */, 4, 5, 321, session)); }
@Test @Override public void testCastToTime() { assertFunction("cast(TIME '03:04:05.321 +07:09' as time)", TIME, sqlTimeOf(3, 4, 5, 321, session)); }
@Test @Override public void testCastToTime() { assertFunction("cast(TIME '03:04:05.321 +07:09' as time)", TIME, sqlTimeOf(2 /* not 3 */, 4, 5, 321, session)); }
@Test public void testCastToTime() { assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321' as time)", TIME, sqlTimeOf(3, 4, 5, 321, session)); }
@Test public void testLiteral() { assertFunction("TIME '03:04:05.321'", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("TIME '03:04:05'", TIME, sqlTimeOf(3, 4, 5, 0, session)); assertFunction("TIME '03:04'", TIME, sqlTimeOf(3, 4, 0, 0, session)); assertInvalidFunction("TIME 'text'", SemanticErrorCode.INVALID_LITERAL, "line 1:1: 'text' is not a valid time literal"); }
@Test @Override public void testCastToTime() { assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 +07:09' as time)", TIME, sqlTimeOf(3, 4, 5, 321, session)); functionAssertions.assertFunctionString("cast(TIMESTAMP '2001-1-22 03:04:05.321 +07:09' as time)", TIME, "03:04:05.321"); }
@Test public void testTimeMinusInterval() { assertFunction("TIME '03:04:05.321' - INTERVAL '3' hour", TIME, sqlTimeOf(0, 4, 5, 321, session)); assertFunction("TIME '03:04:05.321' - INTERVAL '3' day", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("TIME '03:04:05.321' - INTERVAL '3' month", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("TIME '03:04:05.321' - INTERVAL '3' year", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("TIME '03:04:05.321' - INTERVAL '6' hour", TIME, sqlTimeOf(21, 4, 5, 321, session)); assertFunction("TIME '03:04:05.321 +05:09' - INTERVAL '3' hour", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 0, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY)); assertFunction("TIME '03:04:05.321 +05:09' - INTERVAL '3' day", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY)); assertFunction("TIME '03:04:05.321 +05:09' - INTERVAL '3' month", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY)); assertFunction("TIME '03:04:05.321 +05:09' - INTERVAL '3' year", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY)); assertFunction("TIME '03:04:05.321 +05:09' - INTERVAL '6' hour", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 21, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY)); }
@Test public void testTimePlusInterval() assertFunction("TIME '03:04:05.321' + INTERVAL '3' hour", TIME, sqlTimeOf(6, 4, 5, 321, session)); assertFunction("INTERVAL '3' hour + TIME '03:04:05.321'", TIME, sqlTimeOf(6, 4, 5, 321, session)); assertFunction("TIME '03:04:05.321' + INTERVAL '3' day", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("INTERVAL '3' day + TIME '03:04:05.321'", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("TIME '03:04:05.321' + INTERVAL '3' month", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("INTERVAL '3' month + TIME '03:04:05.321'", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("TIME '03:04:05.321' + INTERVAL '3' year", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("INTERVAL '3' year + TIME '03:04:05.321'", TIME, sqlTimeOf(3, 4, 5, 321, session)); assertFunction("TIME '03:04:05.321' + INTERVAL '27' hour", TIME, sqlTimeOf(6, 4, 5, 321, session)); assertFunction("INTERVAL '27' hour + TIME '03:04:05.321'", TIME, sqlTimeOf(6, 4, 5, 321, session));