date issue fixed

This commit is contained in:
2025-07-15 20:57:57 +05:30
parent 5dd7f61cd0
commit 2bd1bc65cd
4 changed files with 75 additions and 31 deletions

View File

@@ -1,6 +1,11 @@
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import { useQuery, useMutation } from "@tanstack/react-query"; import { useQuery, useMutation } from "@tanstack/react-query";
import { format, addDays, startOfToday, addMinutes } from "date-fns"; import { format, addDays, startOfToday, addMinutes } from "date-fns";
import {
parseLocalDateString,
formatLocalDate,
normalizeToISOString
} from "@/utils/dateUtils";
import { TopAppBar } from "@/components/layout/top-app-bar"; import { TopAppBar } from "@/components/layout/top-app-bar";
import { Sidebar } from "@/components/layout/sidebar"; import { Sidebar } from "@/components/layout/sidebar";
import { AddAppointmentModal } from "@/components/appointments/add-appointment-modal"; import { AddAppointmentModal } from "@/components/appointments/add-appointment-modal";
@@ -372,30 +377,11 @@ export default function AppointmentsPage() {
) => { ) => {
// Converts local date to exact UTC date with no offset issues // Converts local date to exact UTC date with no offset issues
function parseLocalDate(dateInput: Date | string): Date { const rawDate = parseLocalDateString(appointmentData.date);
if (dateInput instanceof Date) return dateInput;
const parts = dateInput.split("-");
if (parts.length !== 3) {
throw new Error(`Invalid date format: ${dateInput}`);
}
const year = Number(parts[0]);
const month = Number(parts[1]);
const day = Number(parts[2]);
if (Number.isNaN(year) || Number.isNaN(month) || Number.isNaN(day)) {
throw new Error(`Invalid date parts in date string: ${dateInput}`);
}
return new Date(year, month - 1, day); // month is 0-indexed
}
const rawDate = parseLocalDate(appointmentData.date);
const updatedData = { const updatedData = {
...appointmentData, ...appointmentData,
date: rawDate.toLocaleDateString("en-CA"), date: formatLocalDate(rawDate),
}; };
// Check if we're editing an existing appointment with a valid ID // Check if we're editing an existing appointment with a valid ID
@@ -458,15 +444,7 @@ export default function AppointmentsPage() {
? new Date(appointment.date) ? new Date(appointment.date)
: appointment.date; : appointment.date;
// Extract UTC year, month, day return formatLocalDate(dateObj) === formatLocalDate(selectedDate); // formattedDate should be 'yyyy-MM-dd' string in UTC format as well
const year = dateObj.getUTCFullYear();
const month = dateObj.getUTCMonth(); // zero-based
const day = dateObj.getUTCDate();
// Create a date string in UTC format
const utcDateStr = `${year}-${String(month + 1).padStart(2, "0")}-${String(day).padStart(2, "0")}`;
return utcDateStr === formattedDate; // formattedDate should be 'yyyy-MM-dd' string in UTC format as well
}); });
// Process appointments for the scheduler view // Process appointments for the scheduler view

View File

@@ -33,6 +33,7 @@ import {
clearTaskStatus, clearTaskStatus,
} from "@/redux/slices/seleniumEligibilityCheckTaskSlice"; } from "@/redux/slices/seleniumEligibilityCheckTaskSlice";
import { SeleniumTaskBanner } from "@/components/claims/selenium-task-banner"; import { SeleniumTaskBanner } from "@/components/claims/selenium-task-banner";
import { formatLocalDate } from "@/utils/dateUtils";
const PatientSchema = ( const PatientSchema = (
PatientUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any> PatientUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
@@ -167,7 +168,7 @@ export default function InsuranceEligibilityPage() {
// handle selenium // handle selenium
const handleSelenium = async () => { const handleSelenium = async () => {
const formattedDob = dateOfBirth ? format(dateOfBirth, "yyyy-MM-dd") : ""; const formattedDob = dateOfBirth ? formatLocalDate(dateOfBirth) : "";
const data = {memberId, dateOfBirth: formattedDob, insuranceSiteKey: "MH", }; const data = {memberId, dateOfBirth: formattedDob, insuranceSiteKey: "MH", };
try { try {

View File

@@ -0,0 +1,62 @@
import { format } from "date-fns";
/**
* Parse a date string in yyyy-MM-dd format (assumed local) into a JS Date object.
* No timezone conversion is applied. Returns a Date at midnight local time.
*/
export function parseLocalDateString(dateStr: string): Date {
const parts = dateStr.split("-");
// Destructure with fallback
const [yearStr, monthStr, dayStr] = parts;
// Validate all parts are defined and valid strings
if (!yearStr || !monthStr || !dayStr) {
throw new Error("Invalid date string format. Expected yyyy-MM-dd.");
}
const year = parseInt(yearStr, 10);
const month = parseInt(monthStr, 10) - 1; // JS Date months are 0-based
const day = parseInt(dayStr, 10);
if (Number.isNaN(year) || Number.isNaN(month) || Number.isNaN(day)) {
throw new Error("Invalid numeric values in date string.");
}
return new Date(year, month, day);
}
/**
* Format a JS Date object as a `yyyy-MM-dd` string (in local time).
* Useful for saving date-only data without time component.
*/
export function formatLocalDate(date: Date): string {
return format(date, "yyyy-MM-dd");
}
/**
* Get a Date object representing midnight UTC for a given local date.
* Useful for comparing or storing dates consistently across timezones.
*/
export function toUTCDate(date: Date): Date {
return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
}
/**
* Converts a stored UTC date string (e.g. from DB) into a Date object
* and formats it as local yyyy-MM-dd string for UI use.
*/
export function formatUTCDateStringToLocal(dateStr: string): string {
const date = new Date(dateStr); // parsed as UTC
return formatLocalDate(date);
}
/**
* Ensure any date (Date|string) is formatted to ISO string for consistent backend storage.
* If it's already a string, pass through. If it's a Date, convert to ISO.
*/
export function normalizeToISOString(date: Date | string): string {
return date instanceof Date ? date.toISOString() : date;
}

View File

@@ -182,3 +182,6 @@ class AutomationMassHealthEligibilityCheck:
"status": "error", "status": "error",
"message": e "message": e
} }
finally:
self.driver.quit()