blob: d7fbec794d550bd08bd8e0f66840d45957f08e03 [file] [log] [blame]
/********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
export function dateTimeComparator(filterLocalDateAtMidnight: Date, cellValue: string): number {
const dateTimeAsString: string = cellValue;
if (dateTimeAsString == null) return -1;
const cellDate: Date = new Date(dateTimeAsString);
cellDate.setHours(0);
cellDate.setMinutes(0);
cellDate.setSeconds(0);
cellDate.setMilliseconds(0);
if (filterLocalDateAtMidnight.getTime() == cellDate.getTime()) {
return 0;
}
if (cellDate < filterLocalDateAtMidnight) {
return -1;
}
if (cellDate > filterLocalDateAtMidnight) {
return 1;
}
}
export const stringInsensitiveComparator = (firstValue: string, secondValue: string) => {
firstValue = firstValue ? firstValue : '';
secondValue = secondValue ? secondValue : '';
return firstValue.toLowerCase().localeCompare(secondValue.toLowerCase());
};