Files
doneit-web/src/app/services/functions/sort.service.ts
T

49 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-10-18 13:58:26 +01:00
import { Injectable } from '@angular/core';
2021-11-23 16:23:44 +01:00
import { ObjectService } from './object.service';
2021-10-18 13:58:26 +01:00
@Injectable({
providedIn: 'root'
})
export class SortService {
2021-11-23 16:23:44 +01:00
constructor(private ObjectService: ObjectService) { }
2021-10-18 13:58:26 +01:00
sortArrayISODate(myArray: any) {
2023-02-22 13:06:31 +01:00
if(!Array.isArray(myArray)) {
myArray = []
}
2021-10-19 09:18:02 +01:00
if(myArray.length > 0){
return myArray.sort(function (a, b) {
return (a.CreateDate < b.CreateDate) ? -1 : ((a.CreateDate > b.CreateDate) ? 1 : 0);
});
}
2021-10-18 13:58:26 +01:00
}
2022-01-28 15:59:01 +01:00
2021-10-18 13:58:26 +01:00
sortArrayByDate(myArray: any) {
2023-02-22 13:06:31 +01:00
if(!Array.isArray(myArray)) {
myArray = []
}
2021-10-19 09:18:02 +01:00
if(myArray.length > 0){
return myArray.sort(function (a, b) {
return (new Date(a.workflowInstanceDataFields.StartDate) < new Date(b.workflowInstanceDataFields.StartDate)) ? -1 : ((new Date(a.workflowInstanceDataFields.StartDate) > new Date(b.workflowInstanceDataFields.StartDate)) ? 1 : 0);
});
}
2021-10-18 13:58:26 +01:00
}
2021-11-23 16:23:44 +01:00
sortDate(array = [], path: string) {
2023-02-22 13:06:31 +01:00
if(!Array.isArray(array)) {
array = []
}
2021-11-23 16:23:44 +01:00
return array.sort( (a,b)=> {
2022-01-28 19:01:24 +01:00
return (new Date(this.ObjectService.deepFind(a, path)) < new Date(this.ObjectService.deepFind(b, path))) ? -1 : ((new Date(this.ObjectService.deepFind(a, path)) > new Date(this.ObjectService.deepFind(b, path))) ? 1 : 0);
//return new Date(this.ObjectService.deepFind(b, path)).getTime() - new Date(this.ObjectService.deepFind(a, path)).getTime();
2021-11-23 16:23:44 +01:00
})
2022-01-28 19:01:24 +01:00
2021-11-23 16:23:44 +01:00
}
2021-10-18 13:58:26 +01:00
}