I have a function that sets a cookie as follows:
function createCookieWithDuration(name, value, duration) {
const date = new Date();
console.log(`date now: ${date}`);
date.setSeconds(date.getSeconds() + duration);
console.log(`adjusted date by ${duration} seconds: ${date}`);
document.cookie = `${name}=${value}; expires=${date}; path=/`;
}
Now, if I do this line for line in the debugger it works as expected: 
But when I let the script run and log to the console I get 3 minutes added on as well as the seconds:
Is there a weird javascript timing thing that I'm missing here?
from Javascript date.setSeconds working as expected in Debugger but not in script

No comments:
Post a Comment