{"record":{"id":"9bb8f05d327e7ce5","repo":"prestodb/presto","slug":"invalid-timestamp-s","errorCode":null,"errorMessage":"Invalid timestamp '%s'","messagePattern":"Invalid timestamp '(.+?)'","errorType":"error_code","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/util/DateTimeUtils.java","lineNumber":283,"sourceCode":"    {\n        return LEGACY_TIMESTAMP_WITHOUT_TIME_ZONE_FORMATTER.withChronology(getChronology(timeZoneKey)).print(timestamp);\n    }\n\n    public static boolean timestampHasTimeZone(String value)\n    {\n        try {\n            try {\n                TIMESTAMP_WITH_TIME_ZONE_FORMATTER.parseMillis(value);\n                return true;\n            }\n            catch (RuntimeException e) {\n                // `.withZoneUTC()` makes `timestampHasTimeZone` return value independent of JVM zone\n                TIMESTAMP_WITHOUT_TIME_ZONE_FORMATTER.withZoneUTC().parseMillis(value);\n                return false;\n            }\n        }\n        catch (RuntimeException e) {\n            throw new IllegalArgumentException(format(\"Invalid timestamp '%s'\", value));\n        }\n    }\n\n    private static final DateTimeFormatter TIME_FORMATTER;\n    private static final DateTimeFormatter TIME_WITH_TIME_ZONE_FORMATTER;\n\n    static {\n        DateTimeParser[] timeWithoutTimeZoneParser = {\n                DateTimeFormat.forPattern(\"H:m\").getParser(),\n                DateTimeFormat.forPattern(\"H:m:s\").getParser(),\n                DateTimeFormat.forPattern(\"H:m:s.SSS\").getParser()};\n        DateTimePrinter timeWithoutTimeZonePrinter = DateTimeFormat.forPattern(\"HH:mm:ss.SSS\").getPrinter();\n        TIME_FORMATTER = new DateTimeFormatterBuilder().append(timeWithoutTimeZonePrinter, timeWithoutTimeZoneParser).toFormatter().withZoneUTC();\n\n        DateTimeParser[] timeWithTimeZoneParser = {\n                DateTimeFormat.forPattern(\"H:mZ\").getParser(),\n                DateTimeFormat.forPattern(\"H:m Z\").getParser(),\n                DateTimeFormat.forPattern(\"H:m:sZ\").getParser(),","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/util/DateTimeUtils.java#L265-L301","documentation":"DateTimeUtils.timestampHasTimeZone parses a timestamp literal to determine whether it carries a time-zone offset. If the string cannot be parsed by either the timestamp-with-tz or timestamp-without-tz formatter, the original RuntimeException is swallowed and replaced with an IllegalArgumentException whose message embeds the offending value.","triggerScenarios":"Passing a malformed timestamp string to any SQL path that must classify a timestamp literal (e.g. parsing 'TIMESTAMP' literals or casting strings during query planning) — anything that does not match the expected timestamp format such as \"2024-13-45 99:00:00\" or free-form text.","commonSituations":"Hand-written SQL with typos in date literals; data imported with locale-specific formats (DD/MM/YYYY vs YYYY-MM-DD); strings with trailing garbage or missing components; epoch-style or ISO-8601-with-'T' formats the legacy Joda formatter does not accept.","solutions":["Correct the literal to Presto's timestamp format, e.g. '2024-01-31 12:00:00.000' or with offset '2024-01-31 12:00:00 +01:00'","Use try_cast(value AS TIMESTAMP) to get NULL instead of a failure, then inspect NULLs","Pre-normalize strings with date_parse/date_format or from_iso8601_timestamp before classifying","Check that the value has no stray whitespace, 'T' separators, or unsupported timezone names (use numeric offsets)"],"exampleFix":"// before\nlong x = DateTimeUtils.timestampHasTimeZone(\"2024/01/31\");\n// after\nlong x = DateTimeUtils.timestampHasTimeZone(\"2024-01-31 00:00:00\");","handlingStrategy":"try-catch","validationCode":"boolean ok = value != null && value.matches(\"\\\\d{1,4}-\\\\d{2}-\\\\d{2}([ T]\\\\d{2}:\\\\d{2}(:\\\\d{2}(\\\\.\\\\d{1,3})?)?)?([+-]\\\\d{2}:?\\\\d{2})? *$\");","typeGuard":null,"tryCatchPattern":"try { DateTimeUtils.timestampHasTimeZone(value); } catch (IllegalArgumentException e) { log.warn(\"Bad timestamp literal: {}\", value); /* fallback: use try_cast or reject row */ }","preventionTips":["Use try_cast(value AS TIMESTAMP) in SQL instead of direct casts","Normalize external data to ISO 'YYYY-MM-DD HH:mm:ss[.SSS]' before parsing","Reject or scrub strings with AM/PM, locale formats, or trailing garbage upstream","Always pass numeric timezone offsets, not zone names"],"tags":["presto","timestamp","parsing","datetime"],"backgroundTag":"invalid-timestamp-format","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}