public synchronized Time toTime(Calendar cal, String s) throws SQLException {
    // 1) Parse backend string
    if (s == null) {
      return null;
    }
    ParsedTimestamp ts = parseBackendTimestamp(s);
    Calendar useCal = ts.tz != null ? ts.tz : setupCalendar(cal);
    if (ts.tz == null) {
      // When no time zone provided (e.g. time or timestamp)
      // We get the year-month-day from the string, then truncate the day to 1970-01-01
      // This is used for timestamp -> time conversion
      // Note: this cannot be merged with "else" branch since
      // timestamps at which the time flips to/from DST depend on the date
      // For instance, 2000-03-26 02:00:00 is invalid timestamp in Europe/Moscow time zone
      // and the valid one is 2000-03-26 03:00:00. That is why we parse full timestamp
      // then set year to 1970 later
      useCal.set(Calendar.ERA, ts.era);
      useCal.set(Calendar.YEAR, ts.year);
      useCal.set(Calendar.MONTH, ts.month - 1);
      useCal.set(Calendar.DAY_OF_MONTH, ts.day);
    } else {
      // When time zone is given, we just pick the time part and assume date to be 1970-01-01
      // this is used for time, timez, and timestamptz parsing
      useCal.set(Calendar.ERA, GregorianCalendar.AD);
      useCal.set(Calendar.YEAR, 1970);
      useCal.set(Calendar.MONTH, Calendar.JANUARY);
      useCal.set(Calendar.DAY_OF_MONTH, 1);
    }
    useCal.set(Calendar.HOUR_OF_DAY, ts.hour);
    useCal.set(Calendar.MINUTE, ts.minute);
    useCal.set(Calendar.SECOND, ts.second);
    useCal.set(Calendar.MILLISECOND, 0);

    long timeMillis = useCal.getTimeInMillis() + ts.nanos / 1000000;
    if (ts.tz != null || (ts.year == 1970 && ts.era == GregorianCalendar.AD)) {
      // time with time zone has proper time zone, so the value can be returned as is
      return new Time(timeMillis);
    }

    // 2) Truncate date part so in given time zone the date would be formatted as 01/01/1970
    return convertToTime(timeMillis, useCal == null ? null : useCal.getTimeZone());
  }
public synchronized Time toTime ( Calendar cal , String s ) throws SQLException { if ( s == null ) { return null ; } ParsedTimestamp ts = parseBackendTimestamp ( s ) ; Calendar useCal = ts . tz != null ? ts . tz : setupCalendar ( cal ) ; if ( ts . tz == null ) { useCal . set ( Calendar . ERA , ts . era ) ; useCal . set ( Calendar . YEAR , ts . year ) ; useCal . set ( Calendar . MONTH , ts . month - 1 ) ; useCal . set ( Calendar . DAY_OF_MONTH , ts . day ) ; } else { useCal . set ( Calendar . ERA , GregorianCalendar . AD ) ; useCal . set ( Calendar . YEAR , 1970 ) ; useCal . set ( Calendar . MONTH , Calendar . JANUARY ) ; useCal . set ( Calendar . DAY_OF_MONTH , 1 ) ; } useCal . set ( Calendar . HOUR_OF_DAY , ts . hour ) ; useCal . set ( Calendar . MINUTE , ts . minute ) ; useCal . set ( Calendar . SECOND , ts . second ) ; useCal . set ( Calendar . MILLISECOND , 0 ) ; long timeMillis = useCal . getTimeInMillis ( ) + ts . nanos / 1000000 ; if ( ts . tz != null || ( ts . year == 1970 && ts . era == GregorianCalendar . AD ) ) { return new Time ( timeMillis ) ; } return convertToTime ( timeMillis , useCal == null ? null : useCal . getTimeZone ( ) ) ; }
#endif