I have written a function to format a date for me, and I am calling it on a start date and an end date. The intended behavior is for the start date to be calculated with the formatDate function, and then the end date to be calculated. However, in my console, it appears as though the function is called correctly, but then the values are stored both as the end date.
Here is where I am calling the function and setting the variables:
const setTimeAndDate = () => {
let start = formatDate(startTime)
let end = formatDate(endTime)
console.log('in set time and date, the start is: ', start)
console.log('in set time and date, the end is: ', end)
}
And here is the function to format the date:
const formatDate = (time) => {
let hour = parseInt(time.substring(0,2)) // 13:51 -> 13
let minute = parseInt(time.substring(3))
let d = props.date.date
d.setHours(hour)
d.setMinutes(minute)
console.log('in format date func, the time is: ', d)
return d;
}
The console first prints the correct values from the formatDate() function, but when it prints start and end in setTimeAndDate(), they are both the end values. I'm sure this is just a Javascript thing I am misunderstanding, but could someone explain what is happening here?