Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for date math expressions when comparing date and time fields #4889

Open
i-like-robots opened this issue Mar 15, 2024 · 0 comments
Open
Labels
feature request New feature or request

Comments

@i-like-robots
Copy link

i-like-robots commented Mar 15, 2024

Is your feature request related to a problem? Please describe.

We have many users who wish to query data within a relative date range - for example within the last year or 30 days. This currently requires users to dynamically calculate the date, which is fine for scripts, but frustrating for non-automated queries which are run regularly. For example one of our users regularly runs a report to find a list of items which have not been updated within the last 4 weeks:

query {
  systems(
    where: {
      isArchived: false
      team: { code: "ft-interactive/data-journalism-development" }
      lastUpdated_GT: "2024-02-16"
    }
  ) {
    name
    lastUpdated
  }
}

Although they have their query saved for reuse they must remember to manually (and carefully!) amend the value of the lastUpdated filter.

Describe the solution you'd like

Support for resolving simple date math expressions for the Date and DateTime scalars would enable dates and times to be defined in a more user-friendly way. For example, rather than calculating the date 4 weeks ago and writing this as an ISO-8601 string ("2024-02-16") a user could write -4w instead:

query {
  systems(
    where: {
      isArchived: false
      team: { code: "ft-interactive/data-journalism-development" }
      lastUpdated_GT: "-4w"
    }
  ) {
    name
    lastUpdated
  }
}

Other timespans may be written as (when compared to 2024-03-14T14:32:00.000Z):

Description Actual Date Date math expression
Two hours ago 2024-03-14T12:32:00.000Z -2h
Yesterday 2024-03-14 -1d
1 week ago 2024-03-07 -1w
3 months ago 2023-12-15 -3m
2 years ago 2022-03-15 -2y

Describe alternatives you've considered

I cannot think of an alternative for users who cannot write or run dynamic scripts to execute their queries.

Additional context

We use date math expressions in our Elastic/OpenSearch queries and relative time calculations in BigQuery (e.g. TIMESTAMP_ADD(CURRENT_TIMESTAMP, INTERVAL -28 DAY)) so our users are familiar with the capability to specify relative dates and timespans.

I've put together a very quick and naive implementation here.

@i-like-robots i-like-robots added the feature request New feature or request label Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant