diff --git a/lstV2/server/services/eom/controller/getHistoricalInvByDate.ts b/lstV2/server/services/eom/controller/getHistoricalInvByDate.ts index 4ee0cb9..b78b37d 100644 --- a/lstV2/server/services/eom/controller/getHistoricalInvByDate.ts +++ b/lstV2/server/services/eom/controller/getHistoricalInvByDate.ts @@ -80,8 +80,27 @@ export const historicalInvByDate = async ( date: string, includePlantToken: boolean = false, ) => { - const histDate = new Date(date); + console.log(date); + // date format should always be yyyy-MM-dd or yyyy-MM-dd + let splitDate: string[]; + if (date.includes("/")) { + splitDate = date.split("/"); + } else if (date.includes("-")) { + splitDate = date.split("-"); + } else { + return { + success: false, + message: "An invalid date was passed over", + data: [], + }; + } + const year = parseInt(splitDate[0], 10); + const month = parseInt(splitDate[1], 10) - 1; // zero-based months + const day = parseInt(splitDate[2], 10); + const histDate = new Date(year, month, day); + console.log(histDate); + console.log(format(histDate, "yyyy-MM-dd")); const { data, error } = (await tryCatch( db .select()