From 7e1de0e3c29d79ba37b6ab911c398eda0aff57ca Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 28 Jan 2016 12:28:30 +0100 Subject: [PATCH] Fix share default expiration date calculation Now using UTC dates with moment js to accurately add the number of days --- core/js/shareconfigmodel.js | 13 ++++++------- core/js/tests/specs/shareitemmodelSpec.js | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/core/js/shareconfigmodel.js b/core/js/shareconfigmodel.js index 64f18558267..5494feaf7fa 100644 --- a/core/js/shareconfigmodel.js +++ b/core/js/shareconfigmodel.js @@ -8,6 +8,8 @@ * */ +/* global moment */ + (function() { if (!OC.Share) { OC.Share = {}; @@ -73,13 +75,10 @@ getDefaultExpirationDateString: function () { var expireDateString = ''; if (this.get('isDefaultExpireDateEnabled')) { - var date = new Date().getTime(); - var expireAfterMs = this.get('defaultExpireDate') * 24 * 60 * 60 * 1000; - var expireDate = new Date(date + expireAfterMs); - var month = expireDate.getMonth() + 1; - var year = expireDate.getFullYear(); - var day = expireDate.getDate(); - expireDateString = year + "-" + month + '-' + day + ' 00:00:00'; + var date = moment.utc(); + var expireAfterDays = this.get('defaultExpireDate'); + date.add(expireAfterDays, 'days'); + expireDateString = date.format('YYYY-MM-DD 00:00:00'); } return expireDateString; } diff --git a/core/js/tests/specs/shareitemmodelSpec.js b/core/js/tests/specs/shareitemmodelSpec.js index d696b159e47..e1a14bbbe7f 100644 --- a/core/js/tests/specs/shareitemmodelSpec.js +++ b/core/js/tests/specs/shareitemmodelSpec.js @@ -634,8 +634,8 @@ describe('OC.Share.ShareItemModel', function() { password: '', passwordChanged: false, permissions: OC.PERMISSION_READ, - expireDate: '2015-7-24 00:00:00', - shareType: OC.Share.SHARE_TYPE_LINK + expireDate: '2015-07-24 00:00:00', + shareType: OC.Share.SHARE_TYPE_LINK }); expect(updateShareStub.notCalled).toEqual(true); clock.restore(); -- 2.39.5