Skip to content

Commit

Permalink
Remove Timestamp interface
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvdv committed Jun 17, 2022
1 parent 038b763 commit 0cfa36a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
17 changes: 4 additions & 13 deletions src/helpers/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import moment, { Moment } from 'moment';
import { EventAction, EventTreeNode } from '../models/EventAction';
import { EventMessage } from '../models/EventMessage';
import { DateTimeMask } from '../models/filter/FilterInputs';
import { TimeRange, Timestamp } from '../models/Timestamp';
import { TimeRange } from '../models/Timestamp';
import { isEventMessage } from './event';

export function getElapsedTime(
Expand All @@ -42,10 +42,6 @@ export function formatTime(time: string | number) {
return moment.utc(time).format(DateTimeMask.DATE_TIME_MASK);
}

export function timestampToNumber(timestamp: Timestamp): number {
return Math.floor(timestamp.epochSecond * 1000 + timestamp.nano / 1_000_000);
}

export function getTimestampAsNumber(entity: EventAction | EventTreeNode | EventMessage): number {
if (isEventMessage(entity)) return entity.timestamp;
return entity.startTimestamp;
Expand Down Expand Up @@ -106,21 +102,16 @@ export function getRangeFromTimestamp(timestamp: number, interval: number): Time
];
}

export function sortByTimestamp<T extends { timestamp: number | Timestamp }>(
export function sortByTimestamp<T extends { timestamp: number }>(
array: T[],
order: 'desc' | 'asc' = 'desc',
) {
const copiedArray = array.slice();
copiedArray.sort((itemA, itemB) => {
const timestampA =
typeof itemA.timestamp === 'number' ? itemA.timestamp : timestampToNumber(itemA.timestamp);
const timestampB =
typeof itemB.timestamp === 'number' ? itemB.timestamp : timestampToNumber(itemB.timestamp);

if (order === 'desc') {
return timestampB - timestampA;
return itemB.timestamp - itemA.timestamp;
}
return timestampA - timestampB;
return itemA.timestamp - itemB.timestamp;
});
return copiedArray;
}
5 changes: 0 additions & 5 deletions src/models/Timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,4 @@
* limitations under the License.
***************************************************************************** */

export interface Timestamp {
nano: number;
epochSecond: number;
}

export type TimeRange = [number, number];

0 comments on commit 0cfa36a

Please sign in to comment.