Skip to content

Commit c97526f

Browse files
authored
fix(schema-compiler): fix time dimension granularity origin formatting in local timezone (#9071)
* fix integration custom granularities tests * fix postgres drivers tests related to custom granularities * fix granularity origin formatting in local timezone * fix spelling
1 parent cae4ede commit c97526f

File tree

7 files changed

+23
-10
lines changed

7 files changed

+23
-10
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
**Check List**
2-
- [ ] Tests has been run in packages where changes made if available
2+
- [ ] Tests have been run in packages where changes made if available
33
- [ ] Linter has been run for changed code
44
- [ ] Tests for the changes have been added if not covered yet
55
- [ ] Docs have been added / updated if required

packages/cubejs-schema-compiler/src/adapter/Granularity.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export class Granularity {
1313

1414
public readonly granularityInterval: string;
1515

16+
public readonly queryTimezone: string;
17+
1618
public readonly granularityOffset: string | undefined;
1719

1820
public readonly origin: moment.Moment;
@@ -25,6 +27,7 @@ export class Granularity {
2527
) {
2628
this.granularity = timeDimension.granularity;
2729
this.predefinedGranularity = isPredefinedGranularity(this.granularity);
30+
this.queryTimezone = query.timezone;
2831
this.origin = moment.tz(query.timezone).startOf('year'); // Defaults to current year start
2932

3033
if (this.predefinedGranularity) {
@@ -59,7 +62,7 @@ export class Granularity {
5962
* @returns origin date string in Query timezone
6063
*/
6164
public originLocalFormatted(): string {
62-
return this.origin.format('YYYY-MM-DDTHH:mm:ss.SSS');
65+
return this.origin.tz(this.queryTimezone).format('YYYY-MM-DDTHH:mm:ss.SSS');
6366
}
6467

6568
/**

packages/cubejs-schema-compiler/test/integration/clickhouse/custom-granularities.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ describe('Custom Granularities', () => {
4141
granularities:
4242
- name: half_year
4343
interval: 6 months
44+
origin: '2024-01-01' # to keep tests stable across time (year change, etc)
4445
- name: half_year_by_1st_april
4546
interval: 6 months
46-
offset: 3 months
47+
#offset: 3 months
48+
origin: '2024-04-01' # to keep tests stable across time (year change, etc)
4749
- name: two_weeks_by_friday
4850
interval: 2 weeks
4951
origin: '2024-08-23'

packages/cubejs-schema-compiler/test/integration/mssql/custom-granularities.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ describe('Custom Granularities', () => {
3737
granularities:
3838
- name: half_year
3939
interval: 6 months
40+
origin: '2024-01-01' # to keep tests stable across time (year change, etc)
4041
- name: half_year_by_1st_april
4142
interval: 6 months
42-
offset: 3 months
43+
#offset: 3 months
44+
origin: '2024-04-01' # to keep tests stable across time (year change, etc)
4345
- name: two_weeks_by_friday
4446
interval: 2 weeks
4547
origin: '2024-08-23'

packages/cubejs-schema-compiler/test/integration/mysql/custom-granularities.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ describe('Custom Granularities', () => {
3737
granularities:
3838
- name: half_year
3939
interval: 6 months
40+
origin: '2024-01-01' # to keep tests stable across time (year change, etc)
4041
- name: half_year_by_1st_april
4142
interval: 6 months
42-
offset: 3 months
43+
#offset: 3 months
44+
origin: '2024-04-01' # to keep tests stable across time (year change, etc)
4345
- name: two_weeks_by_friday
4446
interval: 2 weeks
4547
origin: '2024-08-23'

packages/cubejs-schema-compiler/test/integration/postgres/custom-granularities.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ describe('Custom Granularities', () => {
3939
granularities:
4040
- name: half_year
4141
interval: 6 months
42+
origin: '2024-01-01' # to keep tests stable across time (year change, etc)
4243
- name: half_year_by_1st_april
4344
interval: 6 months
44-
offset: 3 months
45+
#offset: 3 months
46+
origin: '2024-04-01' # to keep tests stable across time (year change, etc)
4547
- name: two_weeks_by_friday
4648
interval: 2 weeks
4749
origin: '2024-08-23'

packages/cubejs-testing-drivers/fixtures/_schemas.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,13 @@
9393
"granularities": [
9494
{
9595
"name": "half_year",
96-
"interval": "6 months"
96+
"interval": "6 months",
97+
"origin": "2024-01-01"
9798
},
9899
{
99100
"name": "half_year_by_1st_april",
100101
"interval": "6 months",
101-
"offset": "3 months"
102+
"origin": "2024-04-01"
102103
},
103104
{
104105
"name": "two_mo_by_feb",
@@ -119,12 +120,13 @@
119120
"granularities": [
120121
{
121122
"name": "half_year",
122-
"interval": "6 months"
123+
"interval": "6 months",
124+
"origin": "2024-01-01"
123125
},
124126
{
125127
"name": "half_year_by_1st_april",
126128
"interval": "6 months",
127-
"offset": "3 months"
129+
"origin": "2024-04-01"
128130
},
129131
{
130132
"name": "two_mo_by_feb",

0 commit comments

Comments
 (0)