Fix share default expiration date calculation

Now using UTC dates with moment js to accurately add the number of days
This commit is contained in:
Vincent Petry 2016-01-28 12:28:30 +01:00
parent b063ddb05b
commit 7e1de0e3c2
2 changed files with 8 additions and 9 deletions

View File

@ -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;
}

View File

@ -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();