Skip to content

Commit a5f6729

Browse files
committed
fix lint
1 parent e65f81d commit a5f6729

File tree

1 file changed

+44
-44
lines changed
  • packages/cubejs-client-core/src

1 file changed

+44
-44
lines changed

packages/cubejs-client-core/src/time.ts

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,50 @@ export const isPredefinedGranularity = (granularity: TimeDimensionGranularity):
7979
export const DateRegex = /^\d\d\d\d-\d\d-\d\d$/;
8080
export const LocalDateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z?$/;
8181

82+
/**
83+
* Parse PostgreSQL-like interval string into object
84+
* E.g. '2 years 15 months 100 weeks 99 hours 15 seconds'
85+
* Negative units are also supported
86+
* E.g. '-2 months 5 days -10 hours'
87+
*
88+
* TODO: It's copy/paste of parseSqlInterval from @cubejs-backend/shared [time.ts]
89+
* It's not referenced to omit imports of moment.js staff.
90+
* Probably one day we should choose one implementation and reuse it in other places.
91+
*/
92+
export function parseSqlInterval(intervalStr: SqlInterval): ParsedInterval {
93+
const interval: ParsedInterval = {};
94+
const parts = intervalStr.split(/\s+/);
95+
96+
for (let i = 0; i < parts.length; i += 2) {
97+
const value = parseInt(parts[i], 10);
98+
const unit = parts[i + 1];
99+
100+
// Remove ending 's' (e.g., 'days' -> 'day')
101+
const singularUnit = unit.endsWith('s') ? unit.slice(0, -1) : unit;
102+
interval[singularUnit] = value;
103+
}
104+
105+
return interval;
106+
}
107+
108+
/**
109+
* Adds interval to provided date.
110+
* TODO: It's copy/paste of addInterval from @cubejs-backend/shared [time.ts]
111+
* but operates with dayjs instead of moment.js
112+
* @param {dayjs} date
113+
* @param interval
114+
* @returns {dayjs}
115+
*/
116+
export function addInterval(date: dayjs.Dayjs, interval: ParsedInterval): dayjs.Dayjs {
117+
let res = date.clone();
118+
119+
Object.entries(interval).forEach(([key, value]) => {
120+
res = res.add(value, key);
121+
});
122+
123+
return res;
124+
}
125+
82126
export const dayRange = (from: any, to: any, annotations?: Record<string, { granularity?: Granularity }>): DayRange => ({
83127
by: (value: any) => {
84128
const results = [];
@@ -126,50 +170,6 @@ export const dayRange = (from: any, to: any, annotations?: Record<string, { gran
126170
end: internalDayjs(to),
127171
});
128172

129-
/**
130-
* Parse PostgreSQL-like interval string into object
131-
* E.g. '2 years 15 months 100 weeks 99 hours 15 seconds'
132-
* Negative units are also supported
133-
* E.g. '-2 months 5 days -10 hours'
134-
*
135-
* TODO: It's copy/paste of parseSqlInterval from @cubejs-backend/shared [time.ts]
136-
* It's not referenced to omit imports of moment.js staff.
137-
* Probably one day we should choose one implementation and reuse it in other places.
138-
*/
139-
export function parseSqlInterval(intervalStr: SqlInterval): ParsedInterval {
140-
const interval: ParsedInterval = {};
141-
const parts = intervalStr.split(/\s+/);
142-
143-
for (let i = 0; i < parts.length; i += 2) {
144-
const value = parseInt(parts[i], 10);
145-
const unit = parts[i + 1];
146-
147-
// Remove ending 's' (e.g., 'days' -> 'day')
148-
const singularUnit = unit.endsWith('s') ? unit.slice(0, -1) : unit;
149-
interval[singularUnit] = value;
150-
}
151-
152-
return interval;
153-
}
154-
155-
/**
156-
* Adds interval to provided date.
157-
* TODO: It's copy/paste of addInterval from @cubejs-backend/shared [time.ts]
158-
* but operates with dayjs instead of moment.js
159-
* @param {dayjs} date
160-
* @param interval
161-
* @returns {dayjs}
162-
*/
163-
export function addInterval(date: dayjs.Dayjs, interval: ParsedInterval): dayjs.Dayjs {
164-
let res = date.clone();
165-
166-
Object.entries(interval).forEach(([key, value]) => {
167-
res = res.add(value, key);
168-
});
169-
170-
return res;
171-
}
172-
173173
/**
174174
* Adds interval to provided date.
175175
* TODO: It's copy/paste of subtractInterval from @cubejs-backend/shared [time.ts]

0 commit comments

Comments
 (0)