harbor run -t openthoughts/tasktrove-exp-flat25-pseudocode-v2-5k-pseudocode-1767harbor download openthoughts/tasktrove-exp-flat25-pseudocode-v2-5k-pseudocode-1767pseudocode
// Pseudocode specification for implementing EXTRACT(timezone_name from timestamp ...)
BEGIN
// Data structures TYPE ExtractTZFromTimestampNode ts_literal: STRING // content inside the single-quoted timestamp literal
// Parser: extend SQL parser to recognize // extract(timezone_name from timestamp '<ts_literal-with-arbitrary-whitespace>') FUNCTION parse_extract_timezone_from_timestamp(tokens: LIST[STRING]) -> ExtractTZFromTimestampNode // Expect pattern: EXTRACT ( timezone_name FROM TIMESTAMP STRING_LITERAL ) // Allow arbitrary whitespace between tokens inside the quoted literal // Extract the contents of the STRING_LITERAL (including internal tabs/spaces) inner_literal := extract_string_literal(tokens) // returns "'...'" ts_content := unquote(inner_literal) // remove surrounding quotes RETURN ExtractTZFromTimestampNode(ts_literal = ts_content) END FUNCTION
// Helper: split a timestamp literal by whitespace (tabs allowed) FUNCTION split_whitespace(s: STRING) -> LIST[STRING] // Split on any ASCII whitespace (space, tab, newline, etc.) // Return list of non-empty tokens END FUNCTION
// Evaluator: compute the resulting string for ExtractTZFromTimestampNode FUNCTION evaluate(node: ExtractTZFromTimestampNode) -> STRING // ts_literal expected to be like: "YYYY-MM-DD HH:MM " parts := split_whitespace(node.ts_literal) IF length(parts) < 3 THEN RAISE_ERROR "Invalid timestamp format for timezone_name extraction" END IF
date_part := parts[0]
time_part := parts[1]
zone_part := join(parts[2..], " ") // in practice zone has no spaces; join to be robust
// Validate basic date/time formats (basic checks; do not attempt full datetime validation here)
IF NOT matches_regex(date_part, "^[0-9]{4}-[0-9]{2}-[0-9]{2}$") THEN
RAISE_ERROR "Invalid date format in timestamp literal"
END IF
IF NOT matches_regex(time_part, "^[0-9]{2}:[0-9]{2}$") THEN
RAISE_ERROR "Invalid time format in timestamp literal"
END IF
// Determine if zone_part is a named zone or a numeric offset
IF matches_regex(zone_part, "^[+-][0-9]{1,2}:[0-9]{2}$") THEN
// Numeric offset: normalize to ±HH:MM with two-digit hours
normalized := normalize_offset(zone_part)
RETURN normalized
ELSE
// Named time zone: return exactly as provided (case-sensitive)
RETURN zone_part
END IF
END FUNCTION
// Normalization: convert offsets like "-3:00" to "-03:00"; keep sign and minutes FUNCTION normalize_offset(offset_str: STRING) -> STRING sign := offset_str[0] // '+' or '-' rest := substring(offset_str, 1) // e.g., "3:00" or "12:34" split rest by ":" into hours_str, minutes_str IF length(hours_str) == 0 THEN RAISE_ERROR "Invalid offset hours" END IF hours_padded := pad_left(hours_str, 2, '0') // ensure two digits RETURN sign + hours_padded + ":" + minutes_str END FUNCTION
// Helper: simple regex match function (interface provided by the host) FUNCTION matches_regex(s: STRING, pattern: STRING) -> BOOLEAN // Returns true if s matches the regex pattern END FUNCTION
// Helper: join a list of strings with a delimiter FUNCTION join(list: LIST[STRING], delim: STRING) -> STRING // Concatenate list elements separated by delim END FUNCTION
// Tests (test suite plan)
// Test 1: Named zone extraction FUNCTION test_named_zone_extraction() result := execute_sql("SELECT extract(timezone_name from timestamp '2021-05-03 10:00 America/Sao_Paulo')") ASSERT result == "America/Sao_Paulo" END FUNCTION
// Test 2: Numeric offset extraction (with normalization) FUNCTION test_numeric_offset_extraction() result := execute_sql("SELECT extract(timezone_name from timestamp '2021-05-03 10:00 -3:00')") ASSERT result == "-03:00" END FUNCTION
// Test 3: Cross-check against rdb$time_zones FUNCTION test_rdb_time_zones_crosscheck() rows := query("SELECT rdb$time_zone_name FROM rdb$time_zones ORDER BY rdb$time_zone_name") FOR each row IN rows tz := row.rdb$time_zone_name // Build a timestamp with the dynamic zone name; ensure parsing tolerates whitespace ts_literal := "2021-05-03 10:00" + " " + tz // Allow to include tabs in ts_literal if needed by the test harness result := execute_sql("SELECT extract(timezone_name from timestamp '" + ts_literal + "')") ASSERT result == tz END FOR END FUNCTION
// Integration: wire parser to evaluator // On encountering an EXTRACT node with timezone_name from timestamp ... // Use parse_extract_timezone_from_timestamp to build AST // Then evaluate(AST) to obtain final string
// Acceptance criteria mapping: // - SELECT extract(timezone_name from timestamp '2021-05-03 10:00 America/Sao_Paulo') -> "America/Sao_Paulo" // - SELECT extract(timezone_name from timestamp '2021-05-03 10:00 -3:00') -> "-03:00" // - Dynamic cross-check over rdb$time_zones yields consistent results // - No changes to other EXTRACT units
// Deliverables // - Implement parser extension and evaluator for EXTRACT(timezone_name from timestamp ...) // - Normalize numeric offsets to ±HH:MM with two-digit hours // - Tolerate whitespace (including ASCII 9 tabs) inside the quoted timestamp // - Tests: named zone, numeric offset, and dynamic rdb$time_zones cross-check // - Documentation/comments describing new behavior and supported formats
END