MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / parseExtendedTimeParams

Function parseExtendedTimeParams

packages/tools/src/utils/time-params.ts:18–49  ·  view source on GitHub ↗
(
  params: ExtendedTimeParams,
  contextToolTimeRange?: ToolTimeRange
)

Source from the content-addressed store, hash-verified

16 * 优先级: start_time/end_time > contextToolTimeRange
17 */
18export function parseExtendedTimeParams(
19 params: ExtendedTimeParams,
20 contextToolTimeRange?: ToolTimeRange
21): ToolTimeRange | undefined {
22 if (params.start_time || params.end_time) {
23 let startTs: number | undefined
24 let endTs: number | undefined
25
26 if (params.start_time) {
27 const startDate = new Date(params.start_time.replace(' ', 'T'))
28 if (!isNaN(startDate.getTime())) {
29 startTs = Math.floor(startDate.getTime() / 1000)
30 }
31 }
32
33 if (params.end_time) {
34 const endDate = new Date(params.end_time.replace(' ', 'T'))
35 if (!isNaN(endDate.getTime())) {
36 endTs = Math.floor(endDate.getTime() / 1000)
37 }
38 }
39
40 if (startTs !== undefined || endTs !== undefined) {
41 return {
42 startTs: startTs ?? 0,
43 endTs: endTs ?? Math.floor(Date.now() / 1000),
44 }
45 }
46 }
47
48 return contextToolTimeRange
49}

Callers 5

handlerFunction · 0.90
handlerFunction · 0.90
handlerFunction · 0.90
handlerFunction · 0.90
handlerFunction · 0.90

Calls 1

nowMethod · 0.45

Tested by

no test coverage detected