Repository: apache/flink
File: flink-table/flink-table-common/src/main/java/org/apache/flink/table/utils/DateTimeUtils.java (Java)

Code before:
        s = v % 60;
        v /= 60;
        m = v % 60;
        v /= 60;
        h = v % 24;
        v /= 24;
        d = v;
        buf.append((int) d);
        buf.append(' ');
        number(buf, (int) h, 2);
        buf.append(':');
        number(buf, (int) m, 2);
        buf.append(':');
        number(buf, (int) s, 2);
        fraction(buf, scale, ms);
        return buf.toString();
    }

    private static long internalParseTimestampMillis(String dateStr, String format, TimeZone tz) {
        SimpleDateFormat formatter = FORMATTER_CACHE.get(format);
        formatter.setTimeZone(tz);
        try {
            Date date = formatter.parse(dateStr);
            return date.getTime();
        } catch (ParseException e) {
            LOG.debug(
                    String.format(
                            "Exception when parsing datetime string '%s' in format '%s'",
                            dateStr, format));
            return Long.MIN_VALUE;
        }
    }

    // --------------------------------------------------------------------------------------------
    // EXTRACT
    // --------------------------------------------------------------------------------------------

    private static final TimestampType REUSE_TIMESTAMP_TYPE = new TimestampType(9);

    public static long extractFromTimestamp(TimeUnitRange range, TimestampData ts, TimeZone tz) {
        return convertExtract(range, ts, REUSE_TIMESTAMP_TYPE, tz);
    }

    public static long extractFromDate(TimeUnitRange range, long date) {
        return extractFromDate(range, (int) date);
    }

    public static long extractFromDate(TimeUnitRange range, int date) {
        switch (range) {
            case EPOCH:
                return date * 86400L;

Review comment (suggestion):
it looks like same issue could happen with another (timestamp with offset function)
should it be also changed in the same way?
https://github.com/apache/flink/blob/60e67af935265f0ffa47b610593b5a4939a1484d/flink-table/flink-table-common/src/main/java/org/apache/flink/table/utils/DateTimeUtils.java#L802-L814

Code after:
        v /= 60;
        m = v % 60;
        v /= 60;
        h = v % 24;
        v /= 24;
        d = v;
        buf.append((int) d);
        buf.append(' ');
        number(buf, (int) h, 2);
        buf.append(':');
        number(buf, (int) m, 2);
        buf.append(':');
        number(buf, (int) s, 2);
        fraction(buf, scale, ms);
        return buf.toString();
    }

    private static long internalParseTimestampMillis(String dateStr, String format, TimeZone tz) {
        SimpleDateFormat formatter = FORMATTER_CACHE.get(format);
        formatter.setTimeZone(tz);
        try {
            Date date = formatter.parse(dateStr);
            return date.getTime();
        } catch (ParseException e) {
            LOG.debug(
                    String.format(
                            "Exception when parsing datetime string '%s' in format '%s'",
                            dateStr, format));
            return Long.MIN_VALUE;
        }
    }

    // --------------------------------------------------------------------------------------------
    // EXTRACT
    // --------------------------------------------------------------------------------------------

    private static final TimestampType REUSE_TIMESTAMP_TYPE = new TimestampType(9);

    public static long extractFromTimestamp(TimeUnitRange range, TimestampData ts, TimeZone tz) {
        return convertExtract(range, ts, REUSE_TIMESTAMP_TYPE, tz);
    }

    public static long extractFromDate(TimeUnitRange range, long date) {
        return extractFromDate(range, (int) date);
    }

    public static long extractFromDate(TimeUnitRange range, int date) {
        switch (range) {
            case EPOCH:
                return date * 86400L;
            default: