Fix Bug 2296: Newly Created Ns should come first in NG-UI
[osm/NG-UI.git] / src / services / SharedService.ts
index 8abe1d2..e8eac94 100644 (file)
@@ -191,8 +191,12 @@ export class SharedService {
         if (!isNullOrUndefined(date)) {
             const today: Date = new Date();
             const accountDate: Date = new Date(date);
-            return Math.floor((accountDate.getTime() -
-                today.getTime()) / this.epochTime1000 / this.epochTime60 / this.epochTime60 / this.epochTime24);
+            const toasterDate: number = (accountDate.getTime() -
+                today.getTime()) / this.epochTime1000 / this.epochTime60 / this.epochTime60 / this.epochTime24;
+            if (toasterDate >= 0 || toasterDate < 1) {
+                return Math.round(toasterDate);
+            }
+            return Math.floor(toasterDate);
         }
         return this.translateService.instant('N/A');
     }
@@ -464,6 +468,19 @@ export class SharedService {
         }));
     }
 
+    /** Sorting the list based on date @public */
+    public compareFunction = (dir: number, a: string, b: string): number => {
+        const first: number = new Date(a).getTime();
+        const second: number = new Date(b).getTime();
+        if (first < second) {
+            return -1 * dir;
+        }
+        if (first > second) {
+            return dir;
+        }
+        return 0;
+    };
+
     /** Method to validate file extension and size @private */
     private vaildataFileInfo(fileInfo: File, fileType: string): boolean {
         const extension: string = fileInfo.name.substring(fileInfo.name.lastIndexOf('.') + 1);