Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix(db): clickhouse dates (unsure what have happen)

Carl-Gerhard Lindesvärd9d43cc49c470
diff --git a/packages/db/src/clickhouse/client.ts b/packages/db/src/clickhouse/client.ts
index ada760b59..137b78f0e 100644
--- a/packages/db/src/clickhouse/client.ts
+++ b/packages/db/src/clickhouse/client.ts
@@ -183,17 +183,10 @@ export function formatClickhouseDate(
date: Date | string,
skipTime = false,
): string {
- if (typeof date === 'string') {
- if (skipTime) {
- return date.slice(0, 10);
- }
- return date.slice(0, 19).replace('T', ' ');
- }
-
if (skipTime) {
- return date.toISOString().split('T')[0]!;
+ return new Date(date).toISOString().split('T')[0]!;
}
- return date.toISOString().replace('T', ' ').replace(/Z+$/, '');
+ return new Date(date).toISOString().replace('T', ' ').replace(/Z+$/, '');
}
export function toDate(str: string, interval?: IInterval) {
diff --git a/packages/db/src/prisma-client.ts b/packages/db/src/prisma-client.ts
index 9e5e1b5db..2c8525ac5 100644
--- a/packages/db/src/prisma-client.ts
+++ b/packages/db/src/prisma-client.ts
@@ -100,7 +100,8 @@ const getPrismaClient = () => {
return org.subscriptionEndsAt;
}
- return new Date();
+ // Hedge against edge cases :D
+ return new Date(Date.now() + 1000 * 60 * 60 * 24);
},
},
isTrial: {