File tree Expand file tree Collapse file tree
x-pack/plugins/security_solution
server/lib/detection_engine Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+ * or more contributor license agreements. Licensed under the Elastic License;
4+ * you may not use this file except in compliance with the Elastic License.
5+ */
6+
7+ import moment from 'moment' ;
8+ import dateMath from '@elastic/datemath' ;
9+
10+ export const parseScheduleDates = ( time : string ) : moment . Moment | null => {
11+ const isValidDateString = ! isNaN ( Date . parse ( time ) ) ;
12+ const isValidInput = isValidDateString || time . trim ( ) . startsWith ( 'now' ) ;
13+ const formattedDate = isValidDateString
14+ ? moment ( time )
15+ : isValidInput
16+ ? dateMath . parse ( time )
17+ : null ;
18+
19+ return formattedDate ?? null ;
20+ } ;
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import { UUID } from '../types/uuid';
1414import { IsoDateString } from '../types/iso_date_string' ;
1515import { PositiveIntegerGreaterThanZero } from '../types/positive_integer_greater_than_zero' ;
1616import { PositiveInteger } from '../types/positive_integer' ;
17- import { parseScheduleDates } from '../../utils ' ;
17+ import { parseScheduleDates } from '../../parse_schedule_dates ' ;
1818
1919export const author = t . array ( t . string ) ;
2020export type Author = t . TypeOf < typeof author > ;
Original file line number Diff line number Diff line change 44 * you may not use this file except in compliance with the Elastic License.
55 */
66
7- import moment from 'moment' ;
8- import dateMath from '@elastic/datemath' ;
9-
107import { EntriesArray } from '../shared_imports' ;
118import { Type } from './schemas/common/schemas' ;
129
@@ -21,15 +18,3 @@ export const hasNestedEntry = (entries: EntriesArray): boolean => {
2118} ;
2219
2320export const isThresholdRule = ( ruleType : Type ) => ruleType === 'threshold' ;
24-
25- export const parseScheduleDates = ( time : string ) : moment . Moment | null => {
26- const isValidDateString = ! isNaN ( Date . parse ( time ) ) ;
27- const isValidInput = isValidDateString || time . trim ( ) . startsWith ( 'now' ) ;
28- const formattedDate = isValidDateString
29- ? moment ( time )
30- : isValidInput
31- ? dateMath . parse ( time )
32- : null ;
33-
34- return formattedDate ?? null ;
35- } ;
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import { RuleAlertAttributes } from '../signals/types';
1414import { siemRuleActionGroups } from '../signals/siem_rule_action_groups' ;
1515import { scheduleNotificationActions } from './schedule_notification_actions' ;
1616import { getNotificationResultsLink } from './utils' ;
17- import { parseScheduleDates } from '../../../../common/detection_engine/utils ' ;
17+ import { parseScheduleDates } from '../../../../common/detection_engine/parse_schedule_dates ' ;
1818
1919export const rulesNotificationAlertType = ( {
2020 logger,
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ import {
1717 getExceptions ,
1818 sortExceptionItems ,
1919} from './utils' ;
20- import { parseScheduleDates } from '../../../../common/detection_engine/utils ' ;
20+ import { parseScheduleDates } from '../../../../common/detection_engine/parse_schedule_dates ' ;
2121import { RuleExecutorOptions } from './types' ;
2222import { searchAfterAndBulkCreate } from './search_after_bulk_create' ;
2323import { scheduleNotificationActions } from '../notifications/schedule_notification_actions' ;
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import {
1414 SERVER_APP_ID ,
1515} from '../../../../common/constants' ;
1616import { isJobStarted , isMlRule } from '../../../../common/machine_learning/helpers' ;
17- import { parseScheduleDates } from '../../../../common/detection_engine/utils ' ;
17+ import { parseScheduleDates } from '../../../../common/detection_engine/parse_schedule_dates ' ;
1818import { SetupPlugins } from '../../../plugin' ;
1919import { getInputIndex } from './get_input_output_index' ;
2020import {
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import { buildRuleMessageFactory } from './rule_messages';
1313import { ExceptionListClient } from '../../../../../lists/server' ;
1414import { getListArrayMock } from '../../../../common/detection_engine/schemas/types/lists.mock' ;
1515import { getExceptionListItemSchemaMock } from '../../../../../lists/common/schemas/response/exception_list_item_schema.mock' ;
16- import { parseScheduleDates } from '../../../../common/detection_engine/utils ' ;
16+ import { parseScheduleDates } from '../../../../common/detection_engine/parse_schedule_dates ' ;
1717
1818import {
1919 generateId ,
Original file line number Diff line number Diff line change @@ -14,7 +14,8 @@ import { ExceptionListItemSchema } from '../../../../../lists/common/schemas';
1414import { ListArrayOrUndefined } from '../../../../common/detection_engine/schemas/types/lists' ;
1515import { BulkResponse , BulkResponseErrorAggregation , isValidUnit } from './types' ;
1616import { BuildRuleMessage } from './rule_messages' ;
17- import { hasLargeValueList , parseScheduleDates } from '../../../../common/detection_engine/utils' ;
17+ import { parseScheduleDates } from '../../../../common/detection_engine/parse_schedule_dates' ;
18+ import { hasLargeValueList } from '../../../../common/detection_engine/utils' ;
1819import { MAX_EXCEPTION_LIST_SIZE } from '../../../../../lists/common/constants' ;
1920
2021interface SortExceptionsReturn {
You can’t perform that action at this time.
0 commit comments