]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix share default expiration date calculation
authorVincent Petry <pvince81@owncloud.com>
Thu, 28 Jan 2016 11:28:30 +0000 (12:28 +0100)
committerVincent Petry <pvince81@owncloud.com>
Thu, 28 Jan 2016 14:25:34 +0000 (15:25 +0100)
Now using UTC dates with moment js to accurately add the number of days

core/js/shareconfigmodel.js
core/js/tests/specs/shareitemmodelSpec.js

index 64f18558267c294586f3e25ae2674d1a9592a3c2..5494feaf7fa275ca04269abfeefb5381262dc5f7 100644 (file)
@@ -8,6 +8,8 @@
  *
  */
 
+/* global moment */
+
 (function() {
        if (!OC.Share) {
                OC.Share = {};
                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;
                }
index d696b159e471547980df009b8ee44ff5221d43c7..e1a14bbbe7fa1951d21f78709d2e4757feeb3a6a 100644 (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();