import { addHours } from "date-fns";
import { format } from "date-fns-tz";

export const fixTime = (date: any) => {
    /**
     * This fix is when it comes directly from lst
     */
    if (!date) return;
    //const strippedDate = date?.replace("Z", ""); // Remove Z
    //return format(strippedDate, "MM/dd/yyyy hh:mm a");

    const rawDate = new Date(date).toISOString();
    const offsetMinutes = new Date().getTimezoneOffset(); // in minutes
    const offsetHours =
        -offsetMinutes / 60 >= 0 ? offsetMinutes / 60 : -offsetMinutes / 60;

    return format(
        addHours(rawDate, offsetHours).toISOString(),
        "MM/dd/yyyy HH:mm"
    );
};
