Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not an issue, a suggestion... #14

Open
leolems opened this issue Dec 7, 2014 · 1 comment
Open

Not an issue, a suggestion... #14

leolems opened this issue Dec 7, 2014 · 1 comment

Comments

@leolems
Copy link

leolems commented Dec 7, 2014

Now you have cookie time only in nr of days, you could enhance that a little.

The old "days" parameter is renamed to "period".. (it defaults back to the original days).

Now the period can be "4d" or "8h" or "1d4h" or "12" for just 12 days

    if (typeof period === "number") {
        period = period.toString()+"d"
    }
    if (typeof period === "string") {
        var addtime=0, t, i, reg = /([0-9]{1,3}[d|h])/g, arr = period.match(reg);
        for (i=0;i<arr.length;i++) {
            t=arr[i].slice(-1);
            switch(t) {
                case 'h':
                    addtime += (parseInt(arr[i]) * 60 * 60 * 1000)
                    break;
                case 'd':
                default:    
                    addtime += (parseInt(arr[i]) * 24 * 60 * 60 * 1000)
                    break;
            }
        }
      date.setTime(date.getTime() + addtime);
      expires = "; expires=" + date.toUTCString();
    }
@martinstreicher
Copy link

Using the current code, how do you set values so that a cookie is perennial? Days to -1? Or just some large value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants