Skip to content

Commit 7d72978

Browse files
feat(api-gateway): Introduce CUBEJS_DEFAULT_TIMEZONE env (#10178)
* feat(api-gateway): Introduce CUBEJS_DEFAULT_TIMEZONE env with default value of `UTC` * docs: Add `CUBEJS_DEFAULT_TIMEZONE` environment variable --------- Co-authored-by: Igor Lukanin <igor@cube.dev>
1 parent e426f6b commit 7d72978

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

docs/pages/product/apis-integrations/queries.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ All time-based calculations performed by Cube are time zone-aware.
4646

4747
By default, Cube assumes that time values in your queries (e.g., in date range
4848
filters) are in the [UTC time zone][wiki-utc-time-zone]. Similarly, it will use
49-
the same time zone for time dimension values in result sets.
49+
the same time zone for time dimension values in result sets. You can use the
50+
`CUBEJS_DEFAULT_TIMEZONE` environment variable to override it.
5051

51-
You can use the `timezone` option with [REST API][ref-rest-api-query-format-options]
52+
You can also use the `timezone` option with [REST API][ref-rest-api-query-format-options]
5253
or [GraphQL API][ref-ref-graphql-api-args] to specify the time zone for a query.
5354
Also, you can use the [`SQL_UTILS` context variable][ref-sql-utils] to apply the
5455
time zone conversion to dimensions that are not used as time dimensions in a query.

docs/pages/product/configuration/reference/environment-variables.mdx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,25 @@ untrusted environments.
912912

913913
</WarningBox>
914914

915+
## `CUBEJS_DEFAULT_TIMEZONE`
916+
917+
The default [time zone][ref-time-zone] for queries.
918+
919+
| Possible Values | Default in Development | Default in Production |
920+
| ---------------------- | ---------------------- | --------------------- |
921+
| A valid time zone name | `UTC` | `UTC` |
922+
923+
You can set the time zone name in the [TZ Database Name][link-tzdb] format, e.g.,
924+
`America/Los_Angeles`.
925+
926+
<WarningBox>
927+
928+
Increasing the maximum row limit may cause out-of-memory (OOM) crashes and make
929+
Cube susceptible to denial-of-service (DoS) attacks if it's exposed to
930+
untrusted environments.
931+
932+
</WarningBox>
933+
915934
## `CUBEJS_DEFAULT_API_SCOPES`
916935

917936
[API scopes][ref-rest-scopes] used to allow or disallow access to REST API
@@ -1881,3 +1900,5 @@ The port for a Cube deployment to listen to API connections on.
18811900
[ref-mdx-api]: /product/apis-integrations/mdx-api
18821901
[ref-mdx-api-locale]: /product/apis-integrations/mdx-api#measure-format
18831902
[ref-time-dimensions]: /product/data-modeling/reference/dimensions#time
1903+
[ref-time-zone]: /product/apis-integrations/queries#time-zone
1904+
[link-tzdb]: https://en.wikipedia.org/wiki/Tz_database

packages/cubejs-api-gateway/src/query.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ function normalizeQueryCacheMode(query, cacheMode) {
328328
*/
329329
const normalizeQuery = (query, persistent, cacheMode) => {
330330
query = normalizeQueryCacheMode(query, cacheMode);
331+
query.timezone = query.timezone || getEnv('defaultTimezone');
331332
const { error } = querySchema.validate(query);
332333
if (error) {
333334
throw new UserError(`Invalid query format: ${error.message || error.toString()}`);

packages/cubejs-backend-shared/src/env.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ const variables: Record<string, (...args: any) => any> = {
244244
nestedFoldersDelimiter: () => get('CUBEJS_NESTED_FOLDERS_DELIMITER')
245245
.default('')
246246
.asString(),
247+
defaultTimezone: () => get('CUBEJS_DEFAULT_TIMEZONE')
248+
.default('UTC')
249+
.asString(),
247250

248251
/** ****************************************************************
249252
* Common db options *

0 commit comments

Comments
 (0)