Skip to content

Feat: convert day-sized CLI dates with --time-zone - #5820

Open
Ajay-Satish-01 wants to merge 5 commits into
SQLMesh:mainfrom
Ajay-Satish-01:feat/local_tz
Open

Ajay-Satish-01 wants to merge 5 commits into
SQLMesh:mainfrom
Ajay-Satish-01:feat/local_tz

Conversation

@Ajay-Satish-01

@Ajay-Satish-01 Ajay-Satish-01 commented Jun 1, 2026 •

Copy link
Copy Markdown

Description

Solves #5673

Day-sized relative CLI dates such as --start "1 week ago", today, and yesterday are interpreted as local midnight in the timezone passed with --time-zone, then converted to UTC timestamps. After that, --start and --end are normal UTC timestamps. @start_tstz and @start_ds both come from that UTC timestamp.

  • --time-zone is available on plan, render, evaluate, run, audit, and check_intervals
  • Only day-sized relative phrases use the timezone. Sub-day phrases such as "2 hours ago" and absolute dates are unchanged
  • Defaults to UTC when the flag is omitted or set to UTC
  • Documentation is in docs/reference/cli.md for the affected commands

Test Plan

  • pytest tests/utils/test_date.py — LA/Tokyo relative parsing, @start_ds from the UTC timestamp, DST spring-forward and fall-back, hour-grain phrases ignore the timezone, absolute dates stay UTC
  • pytest tests/cli/test_cli.py::test_apply_time_zone_kwargs_converts_day_sized_bounds_to_utc tests/cli/test_cli.py::test_render_today_with_time_zone_uses_local_midnight tests/cli/test_cli.py::test_plan_accepts_time_zone_option tests/cli/test_cli.py::test_plan_rejects_invalid_time_zone

Checklist

  • I have run make style and fixed any issues
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test)
  • My commits are signed off (git commit -s) per the DCO

Signed-off-by: Ajay-Satish-01 <ajay.satishpriya@gmail.com>
@Ajay-Satish-01

Copy link
Copy Markdown
Author

@StuffbyYuki, please review this PR and let me know if anything is required

@cmgoffena13

Copy link
Copy Markdown
Collaborator

Hey @Ajay-Satish-01 , this PR is too big. The only change we need is a CLI flag, plus to_datetime in sqlmesh/utils/date.py using that zone when the phrase is day-sized ("1 week ago", "today", "yesterday"). After that, --start and --end are normal UTC timestamps.

Doc change should not be in macros, please add documentation changes in docs/reference/cli.md for the commands affected.

Please drop the context changes, the time_zone config, and the plan and macro handling. @start_tstz and @start_ds should keep coming from that one UTC timestamp. The Java/Spark work is out of scope for this issue as well. No changes should be made to context here.

Relative start, end, and execution-time values are parsed as local midnight and stored as UTC. Context, config, plan, and macro variables stay on that UTC timestamp.

Signed-off-by: Ajay-Satish-01 <ajay.satishpriya@gmail.com>
@Ajay-Satish-01 Ajay-Satish-01 changed the title tz_issue_fix Feat: convert day-sized CLI dates with --time-zone Oct 21, 2026
@Ajay-Satish-01

Copy link
Copy Markdown
Author

Hey @Ajay-Satish-01 , this PR is too big. The only change we need is a CLI flag, plus to_datetime in sqlmesh/utils/date.py using that zone when the phrase is day-sized ("1 week ago", "today", "yesterday"). After that, --start and --end are normal UTC timestamps.

Doc change should not be in macros, please add documentation changes in docs/reference/cli.md for the commands affected.

Please drop the context changes, the time_zone config, and the plan and macro handling. @start_tstz and @start_ds should keep coming from that one UTC timestamp. The Java/Spark work is out of scope for this issue as well. No changes should be made to context here.

Thanks for letting me know. Just made new changes. Please verify if this is what you intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants