Skip to content

Commit df32aab

Browse files
committed
rename inDbTimeZone to localTimestampToUtc
1 parent 36b836a commit df32aab

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@ export const BUILD_RANGE_START_LOCAL = '__BUILD_RANGE_START_LOCAL';
192192

193193
export const BUILD_RANGE_END_LOCAL = '__BUILD_RANGE_END_LOCAL';
194194

195-
export const inDbTimeZone = (timezone: string, timestampFormat: string, timestamp: string): string | null => {
195+
/**
196+
* Takes timestamp, treat it as time in provided timezone and returns the corresponding timestamp in UTC
197+
*/
198+
export const localTimestampToUtc = (timezone: string, timestampFormat: string, timestamp: string): string | null => {
196199
if (!timestamp) {
197200
return null;
198201
}
@@ -231,7 +234,7 @@ export const inDbTimeZone = (timezone: string, timestampFormat: string, timestam
231234
};
232235

233236
/**
234-
* Takes timestamp in UTC, treat it as local time in provided timezone and returns the corresponding timestamp in UTC
237+
* Takes timestamp in UTC, shift it into provided timezone and returns the corresponding timestamp in UTC
235238
*/
236239
export const utcToLocalTimeZone = (timezone: string, timestampFormat: string, timestamp: string): string | null => {
237240
if (!timestamp) {

packages/cubejs-backend-shared/test/time.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import moment from 'moment-timezone';
2-
import { inDbTimeZone, timeSeries, isPredefinedGranularity, timeSeriesFromCustomInterval } from '../src';
2+
import { localTimestampToUtc, timeSeries, isPredefinedGranularity, timeSeriesFromCustomInterval } from '../src';
33

44
describe('time', () => {
55
it('time series - day', () => {
@@ -179,11 +179,11 @@ describe('time', () => {
179179
});
180180

181181
it('inDbTimeZone', () => {
182-
expect(inDbTimeZone('UTC', 'YYYY-MM-DD[T]HH:mm:ss.SSSSSS[Z]', '2020-01-01T00:00:00.000000')).toEqual(
182+
expect(localTimestampToUtc('UTC', 'YYYY-MM-DD[T]HH:mm:ss.SSSSSS[Z]', '2020-01-01T00:00:00.000000')).toEqual(
183183
'2020-01-01T00:00:00.000000Z'
184184
);
185185

186-
expect(inDbTimeZone('UTC', 'YYYY-MM-DD[T]HH:mm:ss.SSSSSS[Z]', '2020-01-31T23:59:59.999999')).toEqual(
186+
expect(localTimestampToUtc('UTC', 'YYYY-MM-DD[T]HH:mm:ss.SSSSSS[Z]', '2020-01-31T23:59:59.999999')).toEqual(
187187
'2020-01-31T23:59:59.999999Z'
188188
);
189189
});

packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationPartitionRangeLoader.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
reformatInIsoLocal,
99
utcToLocalTimeZone,
1010
timeSeries,
11-
inDbTimeZone,
11+
localTimestampToUtc,
1212
extractDate,
1313
} from '@cubejs-backend/shared';
1414
import { InlineTable, TableStructure } from '@cubejs-backend/base-driver';
@@ -407,7 +407,7 @@ export class PreAggregationPartitionRangeLoader {
407407
const { preAggregationStartEndQueries } = this.preAggregation;
408408
const [startDate, endDate] = await Promise.all(
409409
preAggregationStartEndQueries.map(
410-
async rangeQuery => inDbTimeZone(
410+
async rangeQuery => localTimestampToUtc(
411411
this.preAggregation.timezone,
412412
'YYYY-MM-DDTHH:mm:ss.SSS',
413413
PreAggregationPartitionRangeLoader.extractDate(await this.loadRangeQuery(rangeQuery)),
@@ -427,7 +427,7 @@ export class PreAggregationPartitionRangeLoader {
427427
);
428428
const [rangeStart, rangeEnd] = await Promise.all(
429429
preAggregationStartEndQueries.map(
430-
async (rangeQuery, i) => inDbTimeZone(
430+
async (rangeQuery, i) => localTimestampToUtc(
431431
this.preAggregation.timezone,
432432
'YYYY-MM-DDTHH:mm:ss.SSS',
433433
PreAggregationPartitionRangeLoader.extractDate(
@@ -529,7 +529,7 @@ export class PreAggregationPartitionRangeLoader {
529529
}
530530

531531
public static inDbTimeZone(preAggregationDescription: any, timestamp: string): string {
532-
return inDbTimeZone(preAggregationDescription.timezone, preAggregationDescription.timestampFormat, timestamp);
532+
return localTimestampToUtc(preAggregationDescription.timezone, preAggregationDescription.timestampFormat, timestamp);
533533
}
534534

535535
public static extractDate(data: any): string {

packages/cubejs-schema-compiler/src/adapter/BaseQuery.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import inflection from 'inflection';
1414
import {
1515
FROM_PARTITION_RANGE,
1616
MAX_SOURCE_ROW_LIMIT,
17-
inDbTimeZone,
17+
localTimestampToUtc,
1818
QueryAlias,
1919
getEnv,
2020
timeSeries as timeSeriesBase
@@ -2921,7 +2921,7 @@ export class BaseQuery {
29212921
}
29222922

29232923
inDbTimeZone(date) {
2924-
return inDbTimeZone(this.timezone, this.timestampFormat(), date);
2924+
return localTimestampToUtc(this.timezone, this.timestampFormat(), date);
29252925
}
29262926

29272927
/**

0 commit comments

Comments
 (0)