fix(historical inv): corrected the way the date can come over to allow for yyyy-mm-dd or with /
the date was coming over in utc format somnetimes and others times local. close #1 correction to the date formats
This commit is contained in:
@@ -80,8 +80,27 @@ export const historicalInvByDate = async (
|
|||||||
date: string,
|
date: string,
|
||||||
includePlantToken: boolean = false,
|
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(
|
const { data, error } = (await tryCatch(
|
||||||
db
|
db
|
||||||
.select()
|
.select()
|
||||||
|
|||||||
Reference in New Issue
Block a user