feat(list): accept relative dates in date flags

Description

The date flags on glab issue list, incident list, mr list and ci list only took a full timestamp. !4063 (merged) did point 4 of #8593 and this MR does points 1 to 3.

These flags now accept:

  • A date, like 2026-10-01.
  • An RFC 3339 timestamp, like 2026-10-01T08:00:00Z, as before.
  • A relative date in the GLQL syntax, like -7d (7 days ago) or 2w (2 weeks from now). The units are d, w, m and y.

glab resolves the value and sends a normal timestamp, so this works with every GitLab version.

Behavior to check:

  • A date or a relative date means the start of that day in the local time zone, so --created-before 2026-10-01 leaves out October 1.
  • For the same result on every machine, such as in scripts and CI, use an RFC 3339 timestamp or set TZ=UTC. The help text says this too. For October 1 in Cairo time I get 7 merge requests, and in UTC I get 4.
  • Month ends: one month before March 31 is February 28.
  • An empty value still means no filter on ci list, and is still an error on the other commands.
  • glab work-items list already had this syntax, so I moved its parser to a shared place. It behaves as before, and still resolves relative dates on the server, in the GitLab server time zone.

Closes #8593

How has this been tested?

I tested by hand with a glab built from main and one built from this branch. The calls are read-only and anonymous, on gitlab-org/cli, in Cairo time. I left -R out of the lines below.

Built from main:

$ glab issue list --updated-after -7d
  invalid argument "-7d" for "--updated-after" flag: invalid time format `-7d` must be one of: `2006-01-
  02T15:04:05Z07:00`.

$ glab issue list --created-after 2026-10-01
  invalid argument "2026-10-01" for "--created-after" flag: invalid time format `2026-10-01` must be one of: `2006-01-
  02T15:04:05Z07:00`.

$ glab mr list --created-after -7d
  invalid argument "-7d" for "--created-after" flag: invalid time format `-7d` must be one of: `2006-01-
  02T15:04:05Z07:00`.

$ glab ci list --updated-after=-7d
  parsing time "-7d" as "2006-01-02T15:04:05Z": cannot parse "-7d" as "2006".

Built from this branch, with --per-page 100 --output json and a small script to summarize the JSON:

$ glab issue list --updated-after=-7d
51 items, updated_at from 2026-10-27T01:34:31.124Z to 2026-11-03T03:43:51.336Z

$ glab issue list --updated-after -7d
51 items, updated_at from 2026-10-27T01:34:31.124Z to 2026-11-03T03:43:51.336Z

$ glab issue list --all --created-after 2026-10-01 --created-before 2026-10-02
2 items, created_at from 2026-10-01T07:25:21.239Z to 2026-10-01T08:48:06.066Z

$ glab mr list --all --created-after -7d
88 items, created_at from 2026-10-27T00:13:02.642Z to 2026-11-03T08:09:57.567Z

$ glab mr list --all --created-after 2026-10-01 --created-before 2026-10-02
7 items, created_at from 2026-09-30T21:15:47.916Z to 2026-10-01T13:13:41.749Z

$ glab ci list -a -1d -b 0d
100 items, updated_at from 2026-11-02T03:49:46.33Z to 2026-11-02T21:57:59.808Z

The ci list result reached the --per-page 100 limit, so that window can have more than 100 pipelines.

These return the same results on both builds:

ci list    --updated-after 2026-10-30T00:00:00Z --updated-before 2026-10-31T00:00:00Z        52 items on both
mr list    --all --created-after 2026-10-01T00:00:00Z --created-before 2026-10-02T00:00:00Z   4 items on both
issue list --all --created-after 2026-10-01T00:00:00Z --created-before 2026-10-02T00:00:00Z   2 items on both
work-items list --created-after -7d                                                           16 items on both

Empty values on this branch, accepted or rejected as on main:

$ glab mr list --created-before ""
  invalid argument "" for "--created-before" flag: must be a date (YYYY-MM-DD), an RFC 3339 timestamp, or a relative
  date such as -7d, 2w, -1m, or 1y.

$ glab ci list --updated-after "" --per-page 1 --output json
1 items, updated_at from 2026-11-03T10:12:26.496Z to 2026-11-03T10:12:26.496Z

$ glab ci list --updated-after "  "
  invalid argument "  " for "-a, --updated-after" flag: must be a date (YYYY-MM-DD), an RFC 3339 timestamp, or a
  relative date such as -7d, 2w, -1m, or 1y.

What glab sends with --per-page 1, from a small local proxy that logs the date parameters:

$ TZ=Africa/Cairo glab issue list --updated-after=-7d --created-before 2026-10-01
created_before=2026-10-01T00:00:00+03:00 updated_after=2026-10-27T00:00:00+03:00

$ TZ=UTC glab issue list --updated-after=-7d --created-before 2026-10-01
created_before=2026-10-01T00:00:00Z updated_after=2026-10-27T00:00:00Z

I added unit tests for each flag form and value type, month ends, clocks that change at midnight, and empty values. The tests of each changed package pass, and gofmt and go vet print nothing. The rest runs in the pipeline.

Implemented with AI assistance; I reviewed and tested the changes.

🤖 Generated with Claude Code

Edited by Hamza Hassanain

Merge request reports

Loading
Loading