public static void writeDateTime64(OutputStream output, LocalDateTime value, int scale, TimeZone tz)
            throws IOException {
        long v = ClickHouseChecker.between(
                tz == null || tz.equals(ClickHouseValues.UTC_TIMEZONE) ? value.toEpochSecond(ZoneOffset.UTC)
                        : value.atZone(tz.toZoneId()).toEpochSecond(),
                ClickHouseValues.TYPE_DATE_TIME,
                DATETIME64_MIN,
                scale == 9 ? DATETIME64_9_MAX : DATETIME64_MAX);
        if (ClickHouseChecker.between(scale, ClickHouseValues.PARAM_SCALE, 0, 9) > 0) {
            v *= BASES[scale];
            int nanoSeconds = value.getNano();
            if (nanoSeconds > 0L) {
                v += nanoSeconds / BASES[9 - scale];
            }
        }

        writeInt64(output, v);
    }
Write a {@link java.time.LocalDateTime} to given output stream.

@param output non-null output stream
@param value  local datetime
@param scale  scale of the datetime, must between 0 and 9 inclusive
@param tz     time zone, null is treated as UTC
@throws IOException when failed to write value to output stream or reached
                    end of the stream
clickhouse-data/src/main/java/com/clickhouse/data/format/BinaryStreamUtils.java