HTML5 Data Bindings State Management Support Product Page
calculating cookie dates
Reported 23 May 2018 09:01:34
1
has this problem
23 May 2018 09:01:34 Greta Garberini posted:
Hi, I need to calculate cookies so for example set cookie like onClick="dmxStateManagementAction('setCookie','mind','confirmed',({path:"/", type:"date", unit:"12", interval:"mm"}))"obviously should produce a 12 month interval (starting as of May, 23rd 2018), whereas it produces an expiration date of "Thu, 23 May 2052 08:57:55 GMT"
Has there been an update I was not aware of or did I miss something else?
Current code is:
function dmxStateManagementAction(action, name, value, cookie, scope) { // v1.00
var evt = jQuery.event.fix(window.event || arguments.callee.caller.arguments[0]),
args = [name, value], db = jQuery.dmxDataBindings;
if (cookie) {
if (cookie.type == 'date' && cookie.interval && cookie.unit) {
var nd = new Date();
switch(cookie.interval) {
case 'y' : nd.setFullYear(nd.getFullYear() + cookie.unit); break;
case 'mm': nd.setMonth(nd.getMonth() + cookie.unit); break;
case 'h' : nd.setTime(nd.getTime() + cookie.unit*3600000); break;
case 'm' : nd.setTime(nd.getTime() + cookie.unit*60000); break;
default : nd.setDate(nd.getDate() + cookie.unit); break;
}
args.push(nd);
} else {
args.push(null);
}
args.push(cookie.path ? cookie.path : null);
args.push(cookie.domain ? cookie.domain : null);
args.push(cookie.secure ? cookie.secure : null);
}
if (db) db[action].apply(scope, args);
evt.preventDefault();
}