public static T convertToSqlType()

in src/main/java/com/aliyun/odps/jdbc/utils/Utils.java [189:221]


  public static <T> T convertToSqlType(Object object, Class<T> type, TimeZone timeZone) {
    if (object == null) {
      return null;
    }
    if (type == String.class) {
      return (T) Objects.toString(object);
    }
    if (object instanceof ZonedDateTime) {
      ZonedDateTime zonedDateTime = (ZonedDateTime) object;
      ZonedDateTime utcZonedDateTime = zonedDateTime.withZoneSameInstant(timeZone.toZoneId());

      if (type == ZonedDateTime.class) {
        return (T) utcZonedDateTime;
      } else if (type == LocalDateTime.class) {
        return (T) utcZonedDateTime.toLocalDateTime();
      }
    } else if (object instanceof LocalDateTime) {
      LocalDateTime localDateTime = (LocalDateTime) object;

      if (type == ZonedDateTime.class) {
        return (T) localDateTime.atZone(timeZone.toZoneId());
      }
    } else if (object instanceof Instant) {
      Instant instant = (Instant) object;
      if (type == LocalDateTime.class) {
        return (T) LocalDateTime.ofInstant(instant, timeZone.toZoneId());
      } else if (type == ZonedDateTime.class) {
        return (T) LocalDateTime.ofInstant(instant, timeZone.toZoneId())
            .atZone(timeZone.toZoneId());
      }
    }
    return (T) object;
  }