Skip to content
This repository was archived by the owner on May 7, 2026. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,61 @@
- `to_timestamp_micros(<int_column>)`
- `to_timestamp_nanos(<int_column>)`
- `to_timestamp_seconds(<int_column>)`

### DATE AND TIME OUTPUT FORMATTING ###
When grouping results by year, month, or quarter, the output column should be formatted as a human-readable label, not a raw DATE or TIMESTAMP.

Always follow two steps:

1. Bucket the timestamp using DATE_TRUNC
2. Format the bucket into a readable string

#### Month Output ####
Monthly results must be formatted as **yyyy-mm**

Example:
```sql
SELECT
CONCAT(
EXTRACT(year FROM DATE_TRUNC('month', created_at)),
'-',
LPAD(EXTRACT(month FROM DATE_TRUNC('month', created_at)), 2, '0')
) AS txn_month,
COUNT(*) AS order_count
FROM orders
GROUP BY 1
ORDER BY 1
```
Example output:
```
txn_month
2026-01
2026-02
2026-03
```

Notes:
Always bucket with DATE_TRUNC('month', ...) before formatting.
Do not extract year/month directly from the raw timestamp when grouping.


#### Year Output ####
Year values should appear as a 4-digit label.

Example:
```sql
SELECT
CAST(EXTRACT(year FROM DATE_TRUNC('year', created_at)) AS VARCHAR) AS txn_year,
COUNT(*) AS order_count
FROM orders
GROUP BY 1
ORDER BY 1
```

Example output:
```sql
txn_year
2024
2025
2026
```
Comment on lines +22 to +78
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add the missing quarter formatting rule.

This section says the guidance covers year, month, and quarter, but only month and year are actually specified. That leaves quarter groupings under-defined, so the model can still fall back to raw timestamps or inconsistent labels for one of the PR’s target cases. Please add a concrete quarter rule and example output as well, e.g. a stable label like 2026-Q1.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ibis-server/resources/knowledge/instructions/date_and_time_functionality.txt`
around lines 22 - 78, Add a quarter formatting rule similar to the month/year
sections: require bucketing with DATE_TRUNC('quarter', ...) and formatting the
bucket into a stable label like "yyyy-Qn" (e.g., 2026-Q1); reference the
existing patterns using DATE_TRUNC, EXTRACT, CONCAT, and LPAD (and CAST where
used for year) and provide a short example SQL that shows DATE_TRUNC('quarter',
created_at) being formatted into "2026-Q1" as the output label along with
example output lines; ensure the note "Always bucket with DATE_TRUNC('quarter',
...)" is added and mirror the grouping/GROUP BY 1 and ORDER BY 1 conventions
from the month/year examples.