Skip to content

Commit

Permalink
fixed one day off bug?
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheryl Chen authored and Cheryl Chen committed Apr 29, 2024
1 parent e57d984 commit c572952
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/Planner/PlannerEvents/PlannerEvents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ const PlannerEvents = ({ onClose }) => {
const [dataShouldRevalidate, setShouldDataRevalidate] = useState(false);
const plannedEvents = plannedEventsContext[0];

const getUTCDate = (eventDate) => {
const utcDate = new Date(eventDate);
return new Date(utcDate.getTime() + utcDate.getTimezoneOffset() * 60000);
}

const getDayData = async () => {
try {
// console.log('getDayData');
const response = await NPOBackend.get(`/day/${dayId}`);
const responseData = response.data[0];
const [datePart] = responseData.eventDate.split('T');
const dateObj = new Date(responseData.eventDate);
const dateObj = getUTCDate(responseData.eventDate);
// console.log(dateObj);
setDateHeader(dateObj.toLocaleDateString({ year: 'numeric', month: 'short', day: '2-digit' }));
setDayData({id: responseData.id, eventDate: datePart, location: responseData.location, details: responseData.notes});
Expand Down

0 comments on commit c572952

Please sign in to comment.