@fincity/kirun-js 2.3.1 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/engine/function/system/date/DateToEpochTest.ts +74 -0
- package/__tests__/engine/function/system/date/DifferenceOfTimestampsTest.ts +53 -0
- package/__tests__/engine/function/system/date/EpochToDateTest.ts +105 -0
- package/__tests__/engine/function/system/date/GetCurrentTimeStampTest.ts +35 -0
- package/__tests__/engine/function/system/date/GetDateTest.ts +85 -0
- package/__tests__/engine/function/system/date/GetDayTest.ts +85 -0
- package/__tests__/engine/function/system/date/GetFullYearTest.ts +85 -0
- package/__tests__/engine/function/system/date/GetHoursTest.ts +85 -0
- package/__tests__/engine/function/system/date/GetMilliSecondsTest.ts +85 -0
- package/__tests__/engine/function/system/date/GetMinutesTest.ts +85 -0
- package/__tests__/engine/function/system/date/GetMonthTest.ts +85 -0
- package/__tests__/engine/function/system/date/GetSecondsTest.ts +85 -0
- package/__tests__/engine/function/system/date/GetTimeAsArrayTest.ts +59 -0
- package/__tests__/engine/function/system/date/GetTimeAsObjectTest.ts +83 -0
- package/__tests__/engine/function/system/date/GetTimeTest.ts +86 -0
- package/__tests__/engine/function/system/date/IsLeapYearTest.ts +85 -0
- package/__tests__/engine/function/system/date/IsValidISODateTest.ts +79 -0
- package/__tests__/engine/function/system/date/MaximumTimestampTest.ts +55 -0
- package/__tests__/engine/function/system/date/MinimumTimestampTest.ts +54 -0
- package/__tests__/engine/runtime/expression/ExpressionEvaluationTest.ts +5 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/engine/function/system/array/ArrayFunctionRepository.ts +2 -0
- package/src/engine/function/system/date/AbstractDateFunction.ts +104 -0
- package/src/engine/function/system/date/DateFunctionRepository.ts +56 -0
- package/src/engine/function/system/date/DateToEpoch.ts +39 -0
- package/src/engine/function/system/date/DifferenceOfTimestamps.ts +45 -0
- package/src/engine/function/system/date/EpochToDate.ts +76 -0
- package/src/engine/function/system/date/GetCurrentTimeStamp.ts +36 -0
- package/src/engine/function/system/date/GetTimeAsArray.ts +48 -0
- package/src/engine/function/system/date/GetTimeAsObject.ts +66 -0
- package/src/engine/function/system/date/IsValidISODate.ts +43 -0
- package/src/engine/function/system/date/MaximumTimestamp.ts +73 -0
- package/src/engine/function/system/date/MinimumTimestamp.ts +74 -0
- package/src/engine/namespaces/Namespaces.ts +1 -0
- package/src/engine/repository/KIRunFunctionRepository.ts +4 -0
- package/src/engine/repository/KIRunSchemaRepository.ts +1 -0
- package/src/engine/runtime/expression/ExpressionEvaluator.ts +14 -15
- package/src/engine/util/ValidDateTimeUtil.ts +119 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { FunctionExecutionParameters, KIRunFunctionRepository, KIRunSchemaRepository } from "../../../../../src";
|
|
2
|
+
import { DateToEpoch } from "../../../../../src/engine/function/system/date/DateToEpoch";
|
|
3
|
+
|
|
4
|
+
const dte: DateToEpoch = new DateToEpoch();
|
|
5
|
+
|
|
6
|
+
const fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
7
|
+
new KIRunFunctionRepository(),
|
|
8
|
+
new KIRunSchemaRepository()
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
describe('invalid date', () => {
|
|
12
|
+
|
|
13
|
+
test('invalid date one', async () => {
|
|
14
|
+
|
|
15
|
+
fep.setArguments(new Map([['isoDate', 'surendhar']]));
|
|
16
|
+
|
|
17
|
+
await expect( () => dte.execute(fep)).rejects.toThrow();
|
|
18
|
+
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
test('invalid date one', async () => {
|
|
23
|
+
|
|
24
|
+
fep.setArguments(new Map([['isoDate', '2023-02-30T12:12:12.123Z']]));
|
|
25
|
+
|
|
26
|
+
await expect( () => dte.execute(fep)).rejects.toThrow();
|
|
27
|
+
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
describe('valid date', () => {
|
|
33
|
+
|
|
34
|
+
test('valid date one', async () => {
|
|
35
|
+
|
|
36
|
+
fep.setArguments(new Map([['isoDate', '2023-10-21T16:11:50.978Z']]));
|
|
37
|
+
|
|
38
|
+
expect((await dte.execute(fep)).allResults()[0].getResult().get('result')).toBe(1697904710978);
|
|
39
|
+
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('valid date two', async () => {
|
|
43
|
+
|
|
44
|
+
fep.setArguments(new Map([['isoDate', '2507-08-07T11:41:50.000Z']]));
|
|
45
|
+
|
|
46
|
+
expect((await dte.execute(fep)).allResults()[0].getResult().get('result')).toBe(16964941310000);
|
|
47
|
+
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('valid date three', async () => {
|
|
51
|
+
|
|
52
|
+
fep.setArguments(new Map([['isoDate', '1970-01-20T15:13:51.000Z']]));
|
|
53
|
+
|
|
54
|
+
expect((await dte.execute(fep)).allResults()[0].getResult().get('result')).toBe(1696431000);
|
|
55
|
+
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('valid date four', async () => {
|
|
59
|
+
|
|
60
|
+
fep.setArguments(new Map([['isoDate', '2024-02-29T12:13:41.189-12:01']]));
|
|
61
|
+
|
|
62
|
+
expect((await dte.execute(fep)).allResults()[0].getResult().get('result')).toBe(1709252081189);
|
|
63
|
+
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('valid date five', async () => {
|
|
67
|
+
|
|
68
|
+
fep.setArguments(new Map([['isoDate', '2028-02-29T12:13:49.200+02:01']]));
|
|
69
|
+
|
|
70
|
+
expect((await dte.execute(fep)).allResults()[0].getResult().get('result')).toBe(1835431969200);
|
|
71
|
+
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { FunctionExecutionParameters } from '../../../../../src/engine/runtime/FunctionExecutionParameters';
|
|
2
|
+
import { KIRunFunctionRepository, KIRunSchemaRepository } from '../../../../../src';
|
|
3
|
+
import { DifferenceOfTimestamps } from '../../../../../src/engine/function/system/date/DifferenceOfTimestamps';
|
|
4
|
+
|
|
5
|
+
const differenceOfTimestamps: DifferenceOfTimestamps = new DifferenceOfTimestamps();
|
|
6
|
+
|
|
7
|
+
const fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
8
|
+
new KIRunFunctionRepository(),
|
|
9
|
+
new KIRunSchemaRepository()
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
describe('testing DifferenceOfTimestamps for invalid dates', () => {
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
test('invalid date one', async () => {
|
|
17
|
+
|
|
18
|
+
fep.setArguments(new Map([['isoDateOne', '2029-05-95T06:04:18.073Z'], ['isoDateTwo', '2029-05-05T06:04:18.073Z']]));
|
|
19
|
+
|
|
20
|
+
await expect( () => differenceOfTimestamps.execute(fep)).rejects.toThrow();
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('invalid date one', async () => {
|
|
24
|
+
|
|
25
|
+
fep.setArguments(new Map([['isoDateOne', '2029-05-05T06:04:18.073Z']]));
|
|
26
|
+
|
|
27
|
+
await expect( () => differenceOfTimestamps.execute(fep)).rejects.toThrow();
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
describe('testing DifferenceOfTimestamps for valid dates', () => {
|
|
32
|
+
|
|
33
|
+
test('valid one', async () => {
|
|
34
|
+
|
|
35
|
+
fep.setArguments(new Map([['isoDateOne', '2024-09-13T23:52:34.633-05:30'], ['isoDateTwo', '2024-09-13T23:52:34.633Z']]));
|
|
36
|
+
|
|
37
|
+
expect((await differenceOfTimestamps.execute(fep)).allResults()[0].getResult().get('result')).toBe(-330);
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('valid two', async () => {
|
|
41
|
+
|
|
42
|
+
fep.setArguments(new Map([['isoDateOne', '2024-09-13T23:52:34.633-05:30'], ['isoDateTwo', '2024-09-12T23:52:34.633Z']]));
|
|
43
|
+
|
|
44
|
+
expect((await differenceOfTimestamps.execute(fep)).allResults()[0].getResult().get('result')).toBe(-1770);
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('valid three', async () => {
|
|
48
|
+
|
|
49
|
+
fep.setArguments(new Map([['isoDateOne', '2023-09-12T23:52:34.633Z'], ['isoDateTwo', '2024-09-13T23:52:34.633-05:30']]));
|
|
50
|
+
|
|
51
|
+
expect((await differenceOfTimestamps.execute(fep)).allResults()[0].getResult().get('result')).toBe(528810);
|
|
52
|
+
})
|
|
53
|
+
})
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { FunctionExecutionParameters } from '../../../../../src/engine/runtime/FunctionExecutionParameters';
|
|
2
|
+
import { KIRunFunctionRepository, KIRunSchemaRepository } from '../../../../../src';
|
|
3
|
+
import { EpochToDate } from '../../../../../src/engine/function/system/date/EpochToDate';
|
|
4
|
+
|
|
5
|
+
const epochToDate: EpochToDate = new EpochToDate();
|
|
6
|
+
|
|
7
|
+
describe('testing EpochToDateFunction', () => {
|
|
8
|
+
test('Epoch To Date', async () => {
|
|
9
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
10
|
+
new KIRunFunctionRepository(),
|
|
11
|
+
new KIRunSchemaRepository(),
|
|
12
|
+
).setArguments(new Map([['epoch', 1694072117]]));
|
|
13
|
+
|
|
14
|
+
expect((await epochToDate.execute(fep)).allResults()[0].getResult().get('date')).toBe(
|
|
15
|
+
'2023-09-07T07:35:17.000Z',
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('Epoch To Date 2', async () => {
|
|
20
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
21
|
+
new KIRunFunctionRepository(),
|
|
22
|
+
new KIRunSchemaRepository(),
|
|
23
|
+
).setArguments(new Map([['epoch', 1694072117000]]));
|
|
24
|
+
|
|
25
|
+
expect((await epochToDate.execute(fep)).allResults()[0].getResult().get('date')).toBe(
|
|
26
|
+
'2023-09-07T07:35:17.000Z',
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('Epoch To Date 3', async () => {
|
|
31
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
32
|
+
new KIRunFunctionRepository(),
|
|
33
|
+
new KIRunSchemaRepository(),
|
|
34
|
+
).setArguments(new Map([['epoch', 169407211700]]));
|
|
35
|
+
|
|
36
|
+
expect((await epochToDate.execute(fep)).allResults()[0].getResult().get('date')).toBe(
|
|
37
|
+
'7338-04-20T14:48:20.000Z',
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
test('epoch string to date 1', async () => {
|
|
41
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
42
|
+
new KIRunFunctionRepository(),
|
|
43
|
+
new KIRunSchemaRepository(),
|
|
44
|
+
).setArguments(new Map([['epoch', '1696489387']]));
|
|
45
|
+
|
|
46
|
+
expect((await epochToDate.execute(fep)).allResults()[0].getResult().get('date')).toBe(
|
|
47
|
+
'2023-10-05T07:03:07.000Z',
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('epoch string to date 2', async () => {
|
|
52
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
53
|
+
new KIRunFunctionRepository(),
|
|
54
|
+
new KIRunSchemaRepository(),
|
|
55
|
+
).setArguments(new Map([['epoch', 'a1696489387']]));
|
|
56
|
+
|
|
57
|
+
expect(async () =>
|
|
58
|
+
(await epochToDate.execute(fep)).allResults()[0].getResult().get('date'),
|
|
59
|
+
).rejects.toThrowError('Please provide a valid value for epoch.');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('epoch string to date 3', async () => {
|
|
63
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
64
|
+
new KIRunFunctionRepository(),
|
|
65
|
+
new KIRunSchemaRepository(),
|
|
66
|
+
).setArguments(new Map([['epoch', '169648938as7']]));
|
|
67
|
+
|
|
68
|
+
expect((await epochToDate.execute(fep)).allResults()[0].getResult().get('date')).toBe(
|
|
69
|
+
'1975-05-18T12:42:18.000Z',
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('epoch string to date 4 all chars', async () => {
|
|
74
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
75
|
+
new KIRunFunctionRepository(),
|
|
76
|
+
new KIRunSchemaRepository(),
|
|
77
|
+
).setArguments(new Map([['epoch', 'abcdef']]));
|
|
78
|
+
|
|
79
|
+
expect(async () =>
|
|
80
|
+
(await epochToDate.execute(fep)).allResults()[0].getResult().get('date'),
|
|
81
|
+
).rejects.toThrow('Please provide a valid value for epoch.');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('epoch test for large string function', async () => {
|
|
85
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
86
|
+
new KIRunFunctionRepository(),
|
|
87
|
+
new KIRunSchemaRepository(),
|
|
88
|
+
).setArguments(new Map([['epoch', '1696494131']]));
|
|
89
|
+
|
|
90
|
+
expect((await epochToDate.execute(fep)).allResults()[0].getResult().get('date')).toBe(
|
|
91
|
+
'2023-10-05T08:22:11.000Z',
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('epoch test for small string function', async () => {
|
|
96
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
97
|
+
new KIRunFunctionRepository(),
|
|
98
|
+
new KIRunSchemaRepository(),
|
|
99
|
+
).setArguments(new Map([['epoch', '169640']]));
|
|
100
|
+
|
|
101
|
+
expect((await epochToDate.execute(fep)).allResults()[0].getResult().get('date')).toBe(
|
|
102
|
+
'1970-01-02T23:07:20.000Z',
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { FunctionExecutionParameters } from '../../../../../src/engine/runtime/FunctionExecutionParameters';
|
|
2
|
+
import { KIRunFunctionRepository, KIRunSchemaRepository } from '../../../../../src';
|
|
3
|
+
import { GetCurrentTimeStamp } from '../../../../../src/engine/function/system/date/GetCurrentTimeStamp';
|
|
4
|
+
|
|
5
|
+
const gcts: GetCurrentTimeStamp = new GetCurrentTimeStamp();
|
|
6
|
+
|
|
7
|
+
describe('testing GetCurrentTimeStamp', () => {
|
|
8
|
+
test('checking with current time stamp', async () => {
|
|
9
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
10
|
+
new KIRunFunctionRepository(),
|
|
11
|
+
new KIRunSchemaRepository(),
|
|
12
|
+
).setArguments(new Map([]));
|
|
13
|
+
|
|
14
|
+
const d = new Date(Date.now());
|
|
15
|
+
|
|
16
|
+
expect((await gcts.execute(fep)).allResults()[0].getResult().get('date').substring(0,21)).toBe(
|
|
17
|
+
d.toISOString().substring(0,21)
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
describe('testing false case of GetCurrentTimeStamp', () => {
|
|
23
|
+
test('checking with current time stamp', async () => {
|
|
24
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
25
|
+
new KIRunFunctionRepository(),
|
|
26
|
+
new KIRunSchemaRepository(),
|
|
27
|
+
).setArguments(new Map([]));
|
|
28
|
+
|
|
29
|
+
const d = new Date(Date.now()-1000000);
|
|
30
|
+
|
|
31
|
+
expect((await gcts.execute(fep)).allResults()[0].getResult().get('date')).not.toBe(
|
|
32
|
+
d.toISOString()
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
})
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { FunctionExecutionParameters, KIRunFunctionRepository, KIRunSchemaRepository, Namespaces } from "../../../../../src";
|
|
2
|
+
import { AbstractDateFunction } from "../../../../../src/engine/function/system/date/AbstractDateFunction";
|
|
3
|
+
import { DateFunctionRepository } from "../../../../../src/engine/function/system/date/DateFunctionRepository";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const dfr : DateFunctionRepository = new DateFunctionRepository();
|
|
7
|
+
|
|
8
|
+
const fep : FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
9
|
+
new KIRunFunctionRepository(),
|
|
10
|
+
new KIRunSchemaRepository());
|
|
11
|
+
|
|
12
|
+
test('check for invalid dates', async () => {
|
|
13
|
+
|
|
14
|
+
const getDateFunction = await dfr.find(Namespaces.DATE, 'GetDate');
|
|
15
|
+
|
|
16
|
+
if (!getDateFunction) {
|
|
17
|
+
throw new Error("Function not found");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, '2029-15-05T06:04:18.073Z' ]]));
|
|
21
|
+
|
|
22
|
+
await expect( () => getDateFunction.execute(fep)).rejects.toThrow();
|
|
23
|
+
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
test('check for invalid dates', async () => {
|
|
28
|
+
|
|
29
|
+
const getDateFunction = await dfr.find(Namespaces.DATE, 'GetDate');
|
|
30
|
+
|
|
31
|
+
if (!getDateFunction) {
|
|
32
|
+
throw new Error("Function not found");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, false ]]));
|
|
36
|
+
|
|
37
|
+
await expect( () => getDateFunction.execute(fep)).rejects.toThrow();
|
|
38
|
+
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('fetching for valid date' , async () => {
|
|
42
|
+
|
|
43
|
+
const getDateFunction = await dfr.find(Namespaces.DATE, 'GetDate');
|
|
44
|
+
|
|
45
|
+
if (!getDateFunction) {
|
|
46
|
+
throw new Error("Function not found");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633-05:30' ]]));
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
expect( (await getDateFunction.execute(fep)).allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(14);
|
|
53
|
+
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('fetching for valid date' , async () => {
|
|
57
|
+
|
|
58
|
+
const getDateFunction = await dfr.find(Namespaces.DATE, 'GetDate');
|
|
59
|
+
|
|
60
|
+
if (!getDateFunction) {
|
|
61
|
+
throw new Error("Function not found");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633Z' ]]));
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
expect( (await getDateFunction.execute(fep)).allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(13);
|
|
68
|
+
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
test('fetching for valid date' , async () => {
|
|
73
|
+
|
|
74
|
+
const getDateFunction = await dfr.find(Namespaces.DATE, 'GetDate');
|
|
75
|
+
|
|
76
|
+
if (!getDateFunction) {
|
|
77
|
+
throw new Error("Function not found");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, '2023-12-31T07:35:17.000-12:00' ]]));
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
expect( (await getDateFunction.execute(fep)).allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(31);
|
|
84
|
+
|
|
85
|
+
})
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { FunctionExecutionParameters, KIRunFunctionRepository, KIRunSchemaRepository, Namespaces } from "../../../../../src";
|
|
2
|
+
import { AbstractDateFunction } from "../../../../../src/engine/function/system/date/AbstractDateFunction";
|
|
3
|
+
import { DateFunctionRepository } from "../../../../../src/engine/function/system/date/DateFunctionRepository";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const dfr : DateFunctionRepository = new DateFunctionRepository();
|
|
7
|
+
|
|
8
|
+
const fep : FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
9
|
+
new KIRunFunctionRepository(),
|
|
10
|
+
new KIRunSchemaRepository());
|
|
11
|
+
|
|
12
|
+
test('check for invalid dates', async () => {
|
|
13
|
+
|
|
14
|
+
const getDayFunction = await dfr.find(Namespaces.DATE, 'GetDay');
|
|
15
|
+
|
|
16
|
+
if (!getDayFunction) {
|
|
17
|
+
throw new Error("Function not found");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, '2029-05-95T06:04:18.073Z' ]]));
|
|
21
|
+
|
|
22
|
+
await expect( () => getDayFunction.execute(fep)).rejects.toThrow();
|
|
23
|
+
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
test('check for invalid dates', async () => {
|
|
28
|
+
|
|
29
|
+
const getDayFunction = await dfr.find(Namespaces.DATE, 'GetDay');
|
|
30
|
+
|
|
31
|
+
if (!getDayFunction) {
|
|
32
|
+
throw new Error("Function not found");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, 1234 ]]));
|
|
36
|
+
|
|
37
|
+
await expect( () => getDayFunction.execute(fep)).rejects.toThrow();
|
|
38
|
+
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('fetching for valid date' , async () => {
|
|
42
|
+
|
|
43
|
+
const getDayFunction = await dfr.find(Namespaces.DATE, 'GetDay');
|
|
44
|
+
|
|
45
|
+
if (!getDayFunction) {
|
|
46
|
+
throw new Error("Function not found");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633-05:30' ]]));
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
expect( (await getDayFunction.execute(fep)).allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(6);
|
|
53
|
+
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('fetching for valid date' , async () => {
|
|
57
|
+
|
|
58
|
+
const getDayFunction = await dfr.find(Namespaces.DATE, 'GetDay');
|
|
59
|
+
|
|
60
|
+
if (!getDayFunction) {
|
|
61
|
+
throw new Error("Function not found");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-10T23:52:34.633Z' ]]));
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
expect( (await getDayFunction.execute(fep)).allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(2);
|
|
68
|
+
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
test('fetching for valid date' , async () => {
|
|
73
|
+
|
|
74
|
+
const getDayFunction = await dfr.find(Namespaces.DATE, 'GetDay');
|
|
75
|
+
|
|
76
|
+
if (!getDayFunction) {
|
|
77
|
+
throw new Error("Function not found");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, '2023-12-31T07:35:17.000-12:00' ]]));
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
expect( (await getDayFunction.execute(fep)).allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(0);
|
|
84
|
+
|
|
85
|
+
})
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { FunctionExecutionParameters, KIRunFunctionRepository, KIRunSchemaRepository, Namespaces } from "../../../../../src";
|
|
2
|
+
import { AbstractDateFunction } from "../../../../../src/engine/function/system/date/AbstractDateFunction";
|
|
3
|
+
import { DateFunctionRepository } from "../../../../../src/engine/function/system/date/DateFunctionRepository";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const dfr : DateFunctionRepository = new DateFunctionRepository();
|
|
7
|
+
|
|
8
|
+
const fep : FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
9
|
+
new KIRunFunctionRepository(),
|
|
10
|
+
new KIRunSchemaRepository());
|
|
11
|
+
|
|
12
|
+
test('check for invalid dates', async () => {
|
|
13
|
+
|
|
14
|
+
const getFullYearFunction = await dfr.find(Namespaces.DATE, 'GetFullYear');
|
|
15
|
+
|
|
16
|
+
if (!getFullYearFunction) {
|
|
17
|
+
throw new Error("Function not found");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, '2029-15-95T06:04:18.073Z' ]]));
|
|
21
|
+
|
|
22
|
+
await expect( () => getFullYearFunction.execute(fep)).rejects.toThrow();
|
|
23
|
+
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
test('check for invalid dates', async () => {
|
|
28
|
+
|
|
29
|
+
const getFullYearFunction = await dfr.find(Namespaces.DATE, 'GetFullYear');
|
|
30
|
+
|
|
31
|
+
if (!getFullYearFunction) {
|
|
32
|
+
throw new Error("Function not found");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, 987654 ]]));
|
|
36
|
+
|
|
37
|
+
await expect( () => getFullYearFunction.execute(fep)).rejects.toThrow();
|
|
38
|
+
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('fetching for valid date' , async () => {
|
|
42
|
+
|
|
43
|
+
const getFullYearFunction = await dfr.find(Namespaces.DATE, 'GetFullYear');
|
|
44
|
+
|
|
45
|
+
if (!getFullYearFunction) {
|
|
46
|
+
throw new Error("Function not found");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633-05:30' ]]));
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
expect( (await getFullYearFunction.execute(fep)).allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(2024);
|
|
53
|
+
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('fetching for valid date' , async () => {
|
|
57
|
+
|
|
58
|
+
const getFullYearFunction = await dfr.find(Namespaces.DATE, 'GetFullYear');
|
|
59
|
+
|
|
60
|
+
if (!getFullYearFunction) {
|
|
61
|
+
throw new Error("Function not found");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, '2019-09-13T23:52:34.633Z' ]]));
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
expect( (await getFullYearFunction.execute(fep)).allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(2019);
|
|
68
|
+
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
test('fetching for valid date' , async () => {
|
|
73
|
+
|
|
74
|
+
const getFullYearFunction = await dfr.find(Namespaces.DATE, 'GetFullYear');
|
|
75
|
+
|
|
76
|
+
if (!getFullYearFunction) {
|
|
77
|
+
throw new Error("Function not found");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, '2023-12-31T07:35:17.000-12:00' ]]));
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
expect( (await getFullYearFunction.execute(fep)).allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(2023);
|
|
84
|
+
|
|
85
|
+
})
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { FunctionExecutionParameters, KIRunFunctionRepository, KIRunSchemaRepository, Namespaces } from "../../../../../src";
|
|
2
|
+
import { AbstractDateFunction } from "../../../../../src/engine/function/system/date/AbstractDateFunction";
|
|
3
|
+
import { DateFunctionRepository } from "../../../../../src/engine/function/system/date/DateFunctionRepository";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const dfr : DateFunctionRepository = new DateFunctionRepository();
|
|
7
|
+
|
|
8
|
+
const fep : FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
9
|
+
new KIRunFunctionRepository(),
|
|
10
|
+
new KIRunSchemaRepository());
|
|
11
|
+
|
|
12
|
+
test('check for invalid dates', async () => {
|
|
13
|
+
|
|
14
|
+
const getHoursFunction = await dfr.find(Namespaces.DATE, 'GetHours');
|
|
15
|
+
|
|
16
|
+
if (!getHoursFunction) {
|
|
17
|
+
throw new Error("Function not found");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, '2029-02-00T06:04:18.073Z' ]]));
|
|
21
|
+
|
|
22
|
+
await expect( () => getHoursFunction.execute(fep)).rejects.toThrow();
|
|
23
|
+
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
test('check for invalid dates', async () => {
|
|
28
|
+
|
|
29
|
+
const getHoursFunction = await dfr.find(Namespaces.DATE, 'GetHours');
|
|
30
|
+
|
|
31
|
+
if (!getHoursFunction) {
|
|
32
|
+
throw new Error("Function not found");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, 'cvb' ]]));
|
|
36
|
+
|
|
37
|
+
await expect( () => getHoursFunction.execute(fep)).rejects.toThrow();
|
|
38
|
+
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('fetching for valid date' , async () => {
|
|
42
|
+
|
|
43
|
+
const getHoursFunction = await dfr.find(Namespaces.DATE, 'GetHours');
|
|
44
|
+
|
|
45
|
+
if (!getHoursFunction) {
|
|
46
|
+
throw new Error("Function not found");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-01T23:52:34.633-05:30' ]]));
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
expect( (await getHoursFunction.execute(fep)).allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(5);
|
|
53
|
+
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('fetching for valid date' , async () => {
|
|
57
|
+
|
|
58
|
+
const getHoursFunction = await dfr.find(Namespaces.DATE, 'GetHours');
|
|
59
|
+
|
|
60
|
+
if (!getHoursFunction) {
|
|
61
|
+
throw new Error("Function not found");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, '2019-11-13T00:52:34.633Z' ]]));
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
expect( (await getHoursFunction.execute(fep)).allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(0);
|
|
68
|
+
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
test('fetching for valid date' , async () => {
|
|
73
|
+
|
|
74
|
+
const getHoursFunction = await dfr.find(Namespaces.DATE, 'GetHours');
|
|
75
|
+
|
|
76
|
+
if (!getHoursFunction) {
|
|
77
|
+
throw new Error("Function not found");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, '2023-12-31T07:35:17.000-12:00' ]]));
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
expect( (await getHoursFunction.execute(fep)).allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(19);
|
|
84
|
+
|
|
85
|
+
})
|