Skip to content

Commit 276ad0d

Browse files
committed
can set the expiration value directly using string
1 parent 43e25c4 commit 276ad0d

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

angular-cookie.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ angular.module('ipCookie', ['ng']).
88
factory('ipCookie', ['$document',
99
function ($document) {
1010
'use strict';
11-
11+
1212
function tryDecodeURIComponent(value) {
1313
try {
1414
return decodeURIComponent(value);
@@ -42,7 +42,7 @@ factory('ipCookie', ['$document',
4242
// Trying to delete a cookie; set a date far in the past
4343
if (expiresFor === -1) {
4444
options.expires = new Date('Thu, 01 Jan 1970 00:00:00 GMT');
45-
// A new
45+
// A new
4646
} else if (options.expirationUnit !== undefined) {
4747
if (options.expirationUnit === 'hours') {
4848
options.expires.setHours(options.expires.getHours() + expiresFor);
@@ -56,12 +56,18 @@ factory('ipCookie', ['$document',
5656
} else {
5757
options.expires.setDate(options.expires.getDate() + expiresFor);
5858
}
59+
60+
options.expires = options.expires.toUTCString();
5961
}
62+
else if (typeof options.expires !== 'string') {
63+
options.expires = options.expires.toUTCString();
64+
}
65+
6066
return ($document[0].cookie = [
6167
encodeURIComponent(key),
6268
'=',
6369
encodeURIComponent(value),
64-
options.expires ? '; expires=' + options.expires.toUTCString() : '',
70+
options.expires ? '; expires=' + options.expires : '',
6571
options.path ? '; path=' + options.path : '',
6672
options.domain ? '; domain=' + options.domain : '',
6773
options.secure ? '; secure' : ''

0 commit comments

Comments
 (0)