Fix issue with timezones
This commit is contained in:
@@ -32,11 +32,15 @@ export const dashboardRouter = createTRPCRouter({
|
||||
.execute();
|
||||
|
||||
let originalDataIndex = periods.length - 1;
|
||||
let dayToMatch = dayjs(input.startDate).startOf("day");
|
||||
// *SLAMS DOWN GLASS OF WHISKEY* timezones, amirite?
|
||||
let dayToMatch = dayjs(input.startDate || new Date()).add(1, "day");
|
||||
const backfilledPeriods: typeof periods = [];
|
||||
|
||||
// Backfill from now to 14 days ago or the date of the first logged call, whichever is earlier
|
||||
while (backfilledPeriods.length < 14 || originalDataIndex >= 0) {
|
||||
while (
|
||||
backfilledPeriods.length < 14 ||
|
||||
(periods[0]?.period && !dayToMatch.isBefore(periods[0]?.period, "day"))
|
||||
) {
|
||||
const nextOriginalPeriod = periods[originalDataIndex];
|
||||
if (nextOriginalPeriod && dayjs(nextOriginalPeriod?.period).isSame(dayToMatch, "day")) {
|
||||
backfilledPeriods.unshift(nextOriginalPeriod);
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { env } from "~/env.mjs";
|
||||
|
||||
import { default as OriginalOpenAI } from "openai";
|
||||
import { OpenAI } from "openpipe";
|
||||
// import { OpenAI } from "openpipe";
|
||||
|
||||
const openAIConfig = { apiKey: env.OPENAI_API_KEY ?? "dummy-key" };
|
||||
|
||||
// Set a dummy key so it doesn't fail at build time
|
||||
export const openai = env.OPENPIPE_API_KEY
|
||||
? new OpenAI.OpenAI(openAIConfig)
|
||||
: new OriginalOpenAI(openAIConfig);
|
||||
// export const openai = env.OPENPIPE_API_KEY
|
||||
// ? new OpenAI.OpenAI(openAIConfig)
|
||||
// : new OriginalOpenAI(openAIConfig);
|
||||
|
||||
export const openai = new OriginalOpenAI(openAIConfig);
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import dayjs from "dayjs";
|
||||
import duration from "dayjs/plugin/duration";
|
||||
import relativeTime from "dayjs/plugin/relativeTime";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
|
||||
dayjs.extend(duration);
|
||||
dayjs.extend(relativeTime);
|
||||
dayjs.extend(timezone);
|
||||
|
||||
export const formatTimePast = (date: Date) =>
|
||||
dayjs.duration(dayjs(date).diff(dayjs())).humanize(true);
|
||||
|
||||
Reference in New Issue
Block a user