public synchronized String toString(Calendar cal, Timestamp x) { return toString(cal, x, true); }
cal = setupCalendar(cal); long timeMillis = x.getTime(); nanos = 0; timeMillis++; } else if (nanosExceed499(nanos)) { appendDate(sbuf, cal); sbuf.append(' '); appendTime(sbuf, cal, nanos); if (withTimeZone) { appendTimeZone(sbuf, cal); appendEra(sbuf, cal);
public synchronized Date toDate(Calendar cal, String s) throws SQLException { // 1) Parse backend string Timestamp timestamp = toTimestamp(cal, s); if (timestamp == null) { return null; } // Note: infinite dates are handled in convertToDate // 2) Truncate date part so in given time zone the date would be formatted as 00:00 return convertToDate(timestamp.getTime(), cal == null ? null : cal.getTimeZone()); }
public synchronized String toString(Calendar cal, Time x, boolean withTimeZone) { cal = setupCalendar(cal); cal.setTime(x); sbuf.setLength(0); appendTime(sbuf, cal, cal.get(Calendar.MILLISECOND) * 1000000); // The 'time' parser for <= 7.3 doesn't like timezones. if (withTimeZone) { appendTimeZone(sbuf, cal); } return sbuf.toString(); }
public synchronized String toString(Calendar cal, Date x, boolean withTimeZone) { if (x.getTime() == PGStatement.DATE_POSITIVE_INFINITY) { return "infinity"; } else if (x.getTime() == PGStatement.DATE_NEGATIVE_INFINITY) { return "-infinity"; } cal = setupCalendar(cal); cal.setTime(x); sbuf.setLength(0); appendDate(sbuf, cal); appendEra(sbuf, cal); if (withTimeZone) { sbuf.append(' '); appendTimeZone(sbuf, cal); } return sbuf.toString(); }
int start = skipWhitespace(s, 0); // Skip leading whitespace int end = firstNonDigit(s, start); int num; char sep; if (charAt(s, end) == '-') { result.year = number(s, start, end); start = end + 1; // Skip '-' end = firstNonDigit(s, start); result.month = number(s, start, end); sep = charAt(s, end); if (sep != '-') { throw new NumberFormatException("Expected date to be dash-separated, got '" + sep + "'"); end = firstNonDigit(s, start); result.day = number(s, start, end); start = skipWhitespace(s, end); // Skip trailing whitespace if (Character.isDigit(charAt(s, start))) { end = firstNonDigit(s, start); result.hour = number(s, start, end); sep = charAt(s, end); if (sep != ':') {
return null; ParsedTimestamp ts = parseBackendTimestamp(s); Calendar useCal = ts.tz != null ? ts.tz : setupCalendar(cal); if (ts.tz == null) { return convertToTime(timeMillis, useCal == null ? null : useCal.getTimeZone());
/** * Formats {@link LocalDateTime} to be sent to the backend, thus it adds time zone. * Do not use this method in {@link java.sql.ResultSet#getString(int)} * @param localDateTime The local date to format as a String * @return The formatted local date */ public synchronized String toString(LocalDateTime localDateTime) { if (localDateTime.isAfter(MAX_LOCAL_DATETIME)) { return "infinity"; } else if (LocalDateTime.MIN.equals(localDateTime)) { return "-infinity"; } // LocalDateTime is always passed with time zone so backend can decide between timestamp and timestamptz ZonedDateTime zonedDateTime = localDateTime.atZone(getDefaultTz().toZoneId()); return toString(zonedDateTime.toOffsetDateTime()); }
tz = getDefaultTz(); millis = guessTimestamp(millis, tz); return convertToTime(millis, tz); // Ensure date part is 1970-01-01
TimeZone tz = cal.getTimeZone(); if (oid == Oid.TIME || oid == Oid.TIMETZ) { return connection.getTimestampUtils().toTimeBin(tz, this_row[col]); } else if (oid == Oid.TIMESTAMP || oid == Oid.TIMESTAMPTZ) { return connection.getTimestampUtils().convertToTime(timeMillis, tz); } else { throw new PSQLException( return connection.getTimestampUtils().toTime(cal, string);
private LocalDateTime getLocalDateTime(int i) throws SQLException { checkResultSet(i); if (wasNullFlag) { return null; } int col = i - 1; int oid = fields[col].getOID(); if (oid != Oid.TIMESTAMP) { throw new PSQLException( GT.tr("Cannot convert the column of type {0} to requested type {1}.", Oid.toString(oid), "timestamp"), PSQLState.DATA_TYPE_MISMATCH); } if (isBinary(i)) { TimeZone timeZone = getDefaultCalendar().getTimeZone(); return connection.getTimestampUtils().toLocalDateTimeBin(timeZone, this_row[col]); } String string = getString(i); return connection.getTimestampUtils().toLocalDateTime(string); } //JCP! endif
@Override public java.sql.Date getDate(int i, java.util.Calendar cal) throws SQLException { checkResultSet(i); if (wasNullFlag) { return null; } if (cal == null) { cal = getDefaultCalendar(); } if (isBinary(i)) { int col = i - 1; int oid = fields[col].getOID(); TimeZone tz = cal.getTimeZone(); if (oid == Oid.DATE) { return connection.getTimestampUtils().toDateBin(tz, this_row[col]); } else if (oid == Oid.TIMESTAMP || oid == Oid.TIMESTAMPTZ) { // If backend provides just TIMESTAMP, we use "cal" timezone // If backend provides TIMESTAMPTZ, we ignore "cal" as we know true instant value Timestamp timestamp = getTimestamp(i, cal); // Here we just truncate date to 00:00 in a given time zone return connection.getTimestampUtils().convertToDate(timestamp.getTime(), tz); } else { throw new PSQLException( GT.tr("Cannot convert the column of type {0} to requested type {1}.", Oid.toString(oid), "date"), PSQLState.DATA_TYPE_MISMATCH); } } return connection.getTimestampUtils().toDate(cal, getString(i)); }
byte[] val = new byte[4]; TimeZone tz = cal != null ? cal.getTimeZone() : null; connection.getTimestampUtils().toBinDate(tz, val, d); preparedParameters.setBinaryParameter(i, val, Oid.DATE); return; cal = getDefaultCalendar(); bindString(i, connection.getTimestampUtils().toString(cal, d), Oid.UNSPECIFIED);
public synchronized String toString(LocalDate localDate) { if (LocalDate.MAX.equals(localDate)) { return "infinity"; } else if (LocalDate.MIN.equals(localDate)) { return "-infinity"; } sbuf.setLength(0); appendDate(sbuf, localDate); appendEra(sbuf, localDate); return sbuf.toString(); }
public synchronized String toString(LocalTime localTime) { sbuf.setLength(0); if (localTime.isAfter(MAX_TIME)) { return "24:00:00"; } int nano = localTime.getNano(); if (nanosExceed499(nano)) { // Technically speaking this is not a proper rounding, however // it relies on the fact that appendTime just truncates 000..999 nanosecond part localTime = localTime.plus(ONE_MICROSECOND); } appendTime(sbuf, localTime); return sbuf.toString(); }
String timestamp = resultSet.getString(columnIndex); if (zoneId != null && timestamp != null) { object = connection.unwrap(PgConnection.class).getTimestampUtils().toLocalDateTime(timestamp).atZone(zoneId); } else { object = resultSet.getTimestamp(columnIndex);
private static void appendDate(StringBuilder sb, Calendar cal) { int l_year = cal.get(Calendar.YEAR); int l_month = cal.get(Calendar.MONTH) + 1; int l_day = cal.get(Calendar.DAY_OF_MONTH); appendDate(sb, l_year, l_month, l_day); }
private static void appendTime(StringBuilder sb, Calendar cal, int nanos) { int hours = cal.get(Calendar.HOUR_OF_DAY); int minutes = cal.get(Calendar.MINUTE); int seconds = cal.get(Calendar.SECOND); appendTime(sb, hours, minutes, seconds, nanos); }
private void appendTimeZone(StringBuilder sb, java.util.Calendar cal) { int offset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 1000; appendTimeZone(sb, offset); }
timestampUtils = new TimestampUtils(!queryExecutor.getIntegerDateTimes(), new Provider<TimeZone>() { @Override public TimeZone get() {