Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 1 addition & 57 deletions src/plugins/query_enhancements/common/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { isPPLSearchQuery, throwFacetError, formatDate } from './utils';
import { isPPLSearchQuery, throwFacetError } from './utils';
import { Query } from 'src/plugins/data/common';

describe('throwFacetError', () => {
Expand Down Expand Up @@ -113,62 +113,6 @@ describe('throwFacetError', () => {
});
});

describe('formatDate', () => {
it('should format date string with milliseconds', () => {
const dateString = '2025-07-30T20:30:31.567Z';
const result = formatDate(dateString);
expect(result).toBe('2025-07-30 20:30:31.567');
});

it('should format date string with zero milliseconds', () => {
const dateString = '2025-07-30T20:30:31.000Z';
const result = formatDate(dateString);
expect(result).toBe('2025-07-30 20:30:31.000');
});

it('should format date string with single digit milliseconds', () => {
const dateString = '2025-07-30T20:30:31.005Z';
const result = formatDate(dateString);
expect(result).toBe('2025-07-30 20:30:31.005');
});

it('should format date string with double digit milliseconds', () => {
const dateString = '2025-07-30T20:30:31.050Z';
const result = formatDate(dateString);
expect(result).toBe('2025-07-30 20:30:31.050');
});

it('should format date string with maximum milliseconds', () => {
const dateString = '2025-07-30T20:30:31.999Z';
const result = formatDate(dateString);
expect(result).toBe('2025-07-30 20:30:31.999');
});

it('should handle different date formats', () => {
const dateString = '2025-01-01T00:00:00.123Z';
const result = formatDate(dateString);
expect(result).toBe('2025-01-01 00:00:00.123');
});

it('should pad single digit months and days', () => {
const dateString = '2025-01-05T09:08:07.456Z';
const result = formatDate(dateString);
expect(result).toBe('2025-01-05 09:08:07.456');
});

it('should handle leap year dates', () => {
const dateString = '2024-02-29T12:34:56.789Z';
const result = formatDate(dateString);
expect(result).toBe('2024-02-29 12:34:56.789');
});

it('should handle end of year dates', () => {
const dateString = '2025-12-31T23:59:59.999Z';
const result = formatDate(dateString);
expect(result).toBe('2025-12-31 23:59:59.999');
});
});

describe('isPPLSearchQuery', () => {
it('should return false if query language is not PPL', () => {
const query: Query = {
Expand Down
19 changes: 0 additions & 19 deletions src/plugins/query_enhancements/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,6 @@ import {
} from './types';
import { API } from './constants';

export const formatDate = (dateString: string) => {
const date = new Date(dateString);
return (
date.getFullYear() +
'-' +
('0' + (date.getMonth() + 1)).slice(-2) +
'-' +
('0' + date.getDate()).slice(-2) +
' ' +
('0' + date.getHours()).slice(-2) +
':' +
('0' + date.getMinutes()).slice(-2) +
':' +
('0' + date.getSeconds()).slice(-2) +
'.' +
('00' + date.getMilliseconds()).slice(-3)
);
};

export const getFields = (rawResponse: any) => {
return rawResponse.data.schema?.map((field: any, index: any) => ({
...field,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
isFilterDisabled,
TimeRange,
} from '../../../../data/common';
import { formatDate } from '../../../common';

export class FilterUtils {
/**
Expand All @@ -23,9 +22,7 @@ export class FilterUtils {
*/
public static getTimeFilterWhereClause(timeFieldName: string, timeRange: TimeRange): string {
const { fromDate, toDate } = formatTimePickerDate(timeRange, 'YYYY-MM-DD HH:mm:ss.SSS');
return `WHERE \`${timeFieldName}\` >= '${formatDate(
fromDate
)}' AND \`${timeFieldName}\` <= '${formatDate(toDate)}'`;
return `WHERE \`${timeFieldName}\` >= '${fromDate}' AND \`${timeFieldName}\` <= '${toDate}'`;
}

/**
Expand Down