update date utility for localtoUtc fn

This commit is contained in:
pramod.mahajan 2025-09-29 15:20:54 +05:30
parent fdbd81c5e7
commit d1c72291a3

View File

@ -69,12 +69,15 @@ export const normalizeAllowedContentTypes = (allowedContentType) => {
return allowedContentType.split(",");
return [];
};
export function localToUtc(localDateString) {
if (!localDateString || localDateString.trim() === "") return null;
if (!localDateString || typeof localDateString !== "string") return null;
const [day, month, year] = localDateString.split("-");
const date = new Date(`${year}-${month}-${day}T00:00:00`);
const [year, month, day] = localDateString.trim().split("-");
if (!year || !month || !day) return null;
const date = new Date(Number(year), Number(month) - 1, Number(day), 0, 0, 0);
return isNaN(date.getTime()) ? null : date.toISOString();
}