]> source.dussan.org Git - nextcloud-server.git/commitdiff
Implementing moment.js
authorClark Tomlinson <fallen013@gmail.com>
Tue, 26 Aug 2014 18:17:33 +0000 (14:17 -0400)
committerClark Tomlinson <fallen013@gmail.com>
Thu, 28 Aug 2014 13:28:45 +0000 (09:28 -0400)
Updating Usages

Removing unused method

Adding JS Doc

apps/files/js/filelist.js
core/js/js.js
core/js/oc-dialogs.js
settings/js/users/users.js

index 3cbc25fc24b1178dfbdbe0a2a699ebedbefc42da..fd11a80248df7823a8a77c04d721aa41065ee9dc 100644 (file)
                                "class": "modified",
                                "title": formatDate(mtime),
                                "style": 'color:rgb('+modifiedColor+','+modifiedColor+','+modifiedColor+')'
-                       }).text( relative_modified_date(mtime / 1000) ));
+                       }).text(OC.Util.relativeModifiedDate(mtime)));
                        tr.find('.filesize').text(simpleSize);
                        tr.append(td);
                        return tr;
index 60f9cc11a581293dcabbfd4748142419fa8de84e..2b3107ecbbf4761470389f70f0768eeec0fc626f 100644 (file)
@@ -390,11 +390,6 @@ var OC={
                }
        }, 500),
        dialogs:OCdialogs,
-       mtime2date:function(mtime) {
-               mtime = parseInt(mtime,10);
-               var date = new Date(1000*mtime);
-               return date.getDate()+'.'+(date.getMonth()+1)+'.'+date.getFullYear()+', '+date.getHours()+':'+date.getMinutes();
-       },
        
        /**
         * Parses a URL query string into a JS map
@@ -1242,14 +1237,11 @@ function humanFileSize(size, skipSmallSizes) {
 
 /**
  * Format an UNIX timestamp to a human understandable format
- * @param {number} date UNIX timestamp
+ * @param {number} timestamp UNIX timestamp
  * @return {string} Human readable format
  */
-function formatDate(date){
-       if(typeof date=='number'){
-               date=new Date(date);
-       }
-       return $.datepicker.formatDate(datepickerFormatDate, date)+' '+date.getHours()+':'+((date.getMinutes()<10)?'0':'')+date.getMinutes();
+function formatDate(timestamp){
+       return OC.Util.formatDate(timestamp);
 }
 
 // 
@@ -1270,21 +1262,11 @@ function getURLParameter(name) {
  * @param {number} timestamp A Unix timestamp
  */
 function relative_modified_date(timestamp) {
-       var timeDiff = Math.round((new Date()).getTime() / 1000) - timestamp;
-       var diffMinutes = Math.round(timeDiff/60);
-       var diffHours = Math.round(diffMinutes/60);
-       var diffDays = Math.round(diffHours/24);
-       var diffMonths = Math.round(diffDays/31);
-       if(timeDiff < 60) { return t('core','seconds ago'); }
-       else if(timeDiff < 3600) { return n('core','%n minute ago', '%n minutes ago', diffMinutes); }
-       else if(timeDiff < 86400) { return n('core', '%n hour ago', '%n hours ago', diffHours); }
-       else if(timeDiff < 86400) { return t('core','today'); }
-       else if(timeDiff < 172800) { return t('core','yesterday'); }
-       else if(timeDiff < 2678400) { return n('core', '%n day ago', '%n days ago', diffDays); }
-       else if(timeDiff < 5184000) { return t('core','last month'); }
-       else if(timeDiff < 31556926) { return n('core', '%n month ago', '%n months ago', diffMonths); }
-       else if(timeDiff < 63113852) { return t('core','last year'); }
-       else { return t('core','years ago'); }
+       /*
+        Were multiplying by 1000 to bring the timestamp back to its original value
+        per https://github.com/owncloud/core/pull/10647#discussion_r16790315
+         */
+       return OC.Util.relativeModifiedDate(timestamp * 1000);
 }
 
 /**
@@ -1293,7 +1275,24 @@ function relative_modified_date(timestamp) {
 OC.Util = {
        // TODO: remove original functions from global namespace
        humanFileSize: humanFileSize,
-       formatDate: formatDate,
+
+       /**
+        * @param timestamp
+        * @param format
+        * @returns {string} timestamp formatted as requested
+        */
+       formatDate: function (timestamp, format) {
+               format = format || "MMMM D, YYYY h:mm";
+               return moment(timestamp).format(format);
+       },
+
+       /**
+        * @param timestamp
+        * @returns {string} human readable difference from now
+        */
+       relativeModifiedDate: function (timestamp) {
+               return moment(timestamp).fromNow();
+       },
        /**
         * Returns whether the browser supports SVG
         * @return {boolean} true if the browser supports SVG, false otherwise
index 7f87e1a6f3eb46ccc2c3615bda089e145f8fa231..bd6fd2e5007df362818b832751df71805b5abafb 100644 (file)
@@ -635,7 +635,7 @@ var OCdialogs = {
                                        type: entry.type,
                                        dir: dir,
                                        filename: entry.name,
-                                       date: relative_modified_date(entry.mtime/1000)
+                                       date: OC.Util.relativeModifiedDate(entry.mtime)
                                });
                                if (entry.isPreviewAvailable) {
                                        var urlSpec = {
index 60948bb99f31f14cea4f69e689aec824da72796b..0f72746ee83f6ce1c36bec3a3c9a945e0df32b1f 100644 (file)
@@ -96,9 +96,8 @@ var UserList = {
                var lastLoginRel = t('settings', 'never');
                var lastLoginAbs = lastLoginRel;
                if(lastLogin !== 0) {
-                       lastLogin = new Date(lastLogin * 1000);
-                       lastLoginRel = relative_modified_date(lastLogin.getTime() / 1000);
-                       lastLoginAbs = formatDate(lastLogin.getTime());
+                       lastLoginRel = OC.Util.relativeModifiedDate(lastLogin);
+                       lastLoginAbs = OC.Util.formatDate(lastLogin);
                }
                var $tdLastLogin = $tr.find('td.lastLogin');
                $tdLastLogin.text(lastLoginRel);