Files
doneit-web/src/app/services/functions/sort.service.ts
T
Peter Maquiran 2a0744e9ae update chat list
2022-01-28 19:01:24 +01:00

44 lines
1.4 KiB
TypeScript

import { Injectable } from '@angular/core';
import { ObjectService } from './object.service';
@Injectable({
providedIn: 'root'
})
export class SortService {
constructor(private ObjectService: ObjectService) { }
sortArrayISODate(myArray: any) {
if(myArray.length > 0){
return myArray.sort(function (a, b) {
return (a.CreateDate < b.CreateDate) ? -1 : ((a.CreateDate > b.CreateDate) ? 1 : 0);
});
}
}
sortArrayByDate(myArray: any) {
console.log(myArray[0].taskStartDate);
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);
});
}
}
sortDate(array = [], path: string) {
return array.sort( (a,b)=> {
/* console.log("AAA"+new Date(this.ObjectService.deepFind(a, path)));
console.log("BB"+new Date(this.ObjectService.deepFind(b, path))); */
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();
})
}
}