@fincity/kirun-js 2.8.2 → 2.8.4
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/DifferenceTest.ts +52 -5
- package/__tests__/engine/function/system/date/FromDateStringTest.ts +21 -0
- package/__tests__/engine/function/system/date/FromNowTest.ts +3 -3
- package/__tests__/engine/function/system/date/LastFirstOfTest.ts +2 -2
- package/__tests__/engine/function/system/date/SetTimeZoneTest.ts +6 -6
- package/__tests__/engine/function/system/date/StartEndOfTest.ts +44 -4
- package/__tests__/engine/function/system/date/TimeAsTest.ts +1 -1
- package/__tests__/engine/function/system/date/ToDateStringTest.ts +18 -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.map +1 -1
- package/package.json +1 -1
- package/src/engine/function/system/date/DateFunctionRepository.ts +5 -4
- package/src/engine/function/system/date/FromNow.ts +7 -7
- package/src/engine/function/system/date/SetTimeZone.ts +1 -1
- package/src/engine/function/system/date/StartEndOf.ts +6 -6
- package/src/engine/function/system/date/common.ts +1 -1
- package/src/engine/json/schema/validator/SchemaValidator.ts +1 -1
- package/src/engine/repository/KIRunSchemaRepository.ts +16 -16
- package/src/engine/runtime/expression/tokenextractor/TokenValueExtractor.ts +14 -21
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { Settings } from 'luxon';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import {
|
|
3
|
+
FunctionExecutionParameters,
|
|
4
|
+
KIRunFunctionRepository,
|
|
5
|
+
KIRunSchemaRepository,
|
|
6
|
+
Namespaces,
|
|
7
|
+
} from '../../../../../src';
|
|
5
8
|
import { AbstractDateFunction } from '../../../../../src/engine/function/system/date/AbstractDateFunction';
|
|
6
9
|
import { DateFunctionRepository } from '../../../../../src/engine/function/system/date/DateFunctionRepository';
|
|
7
10
|
|
|
@@ -66,7 +69,7 @@ describe('Difference of dates', () => {
|
|
|
66
69
|
|
|
67
70
|
expect(
|
|
68
71
|
result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME),
|
|
69
|
-
).toMatchObject({ months: 8, days:
|
|
72
|
+
).toMatchObject({ months: 8, days: 10, hours: 13, minutes: 30 });
|
|
70
73
|
});
|
|
71
74
|
|
|
72
75
|
test('should return the difference in negative months,days,hours,minutes', async () => {
|
|
@@ -88,6 +91,50 @@ describe('Difference of dates', () => {
|
|
|
88
91
|
|
|
89
92
|
expect(
|
|
90
93
|
result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME),
|
|
91
|
-
).toMatchObject({ months: -
|
|
94
|
+
).toMatchObject({ months: -16, days: 0, hours: -10, minutes: -30 });
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('should return the difference in fractions', async () => {
|
|
98
|
+
const fep = new FunctionExecutionParameters(
|
|
99
|
+
new KIRunFunctionRepository(),
|
|
100
|
+
new KIRunSchemaRepository(),
|
|
101
|
+
).setArguments(
|
|
102
|
+
new Map<string, any>([
|
|
103
|
+
[AbstractDateFunction.PARAMETER_TIMESTAMP_NAME_ONE, '2024-01-01T10:20:30+05:30'],
|
|
104
|
+
[AbstractDateFunction.PARAMETER_TIMESTAMP_NAME_TWO, '2025-04-25T10:20:30-05:00'],
|
|
105
|
+
[AbstractDateFunction.PARAMETER_UNIT_NAME, ['DAYS']],
|
|
106
|
+
]),
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const result = await (await new DateFunctionRepository().find(
|
|
110
|
+
Namespaces.DATE,
|
|
111
|
+
'Difference',
|
|
112
|
+
))!.execute(fep);
|
|
113
|
+
|
|
114
|
+
expect(
|
|
115
|
+
result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME),
|
|
116
|
+
).toMatchObject({ days: -480.4375 });
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('should return the difference in multiple fractions', async () => {
|
|
120
|
+
const fep = new FunctionExecutionParameters(
|
|
121
|
+
new KIRunFunctionRepository(),
|
|
122
|
+
new KIRunSchemaRepository(),
|
|
123
|
+
).setArguments(
|
|
124
|
+
new Map<string, any>([
|
|
125
|
+
[AbstractDateFunction.PARAMETER_TIMESTAMP_NAME_ONE, '2024-01-01T10:20:30+05:30'],
|
|
126
|
+
[AbstractDateFunction.PARAMETER_TIMESTAMP_NAME_TWO, '2025-04-25T09:17:23-05:00'],
|
|
127
|
+
[AbstractDateFunction.PARAMETER_UNIT_NAME, ['DAYS', 'HOURS']],
|
|
128
|
+
]),
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const result = await (await new DateFunctionRepository().find(
|
|
132
|
+
Namespaces.DATE,
|
|
133
|
+
'Difference',
|
|
134
|
+
))!.execute(fep);
|
|
135
|
+
|
|
136
|
+
expect(
|
|
137
|
+
result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME),
|
|
138
|
+
).toMatchObject({ days: -480, hours: -9.448055555554674 });
|
|
92
139
|
});
|
|
93
140
|
});
|
|
@@ -48,4 +48,25 @@ describe('FromDateString', () => {
|
|
|
48
48
|
|
|
49
49
|
expect(result).toEqual('2024-05-01T00:00:00.000+05:30');
|
|
50
50
|
});
|
|
51
|
+
|
|
52
|
+
test('should return the timestamp with the only few fields', async () => {
|
|
53
|
+
const fep = new FunctionExecutionParameters(
|
|
54
|
+
new KIRunFunctionRepository(),
|
|
55
|
+
new KIRunSchemaRepository(),
|
|
56
|
+
).setArguments(
|
|
57
|
+
MapUtil.of(
|
|
58
|
+
FromDateString.PARAMETER_TIMESTAMP_STRING_NAME,
|
|
59
|
+
'03 12 123',
|
|
60
|
+
FromDateString.PARAMETER_FORMAT_NAME,
|
|
61
|
+
'dd ss SSS',
|
|
62
|
+
),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const result = (await fromDateString.execute(fep))
|
|
66
|
+
.allResults()[0]
|
|
67
|
+
.getResult()
|
|
68
|
+
.get(FromDateString.EVENT_RESULT_NAME);
|
|
69
|
+
|
|
70
|
+
expect(result).toEqual('2024-11-03T00:00:12.123+05:30');
|
|
71
|
+
});
|
|
51
72
|
});
|
|
@@ -17,7 +17,7 @@ describe('From Now', () => {
|
|
|
17
17
|
).setArguments(
|
|
18
18
|
new Map([
|
|
19
19
|
[AbstractDateFunction.PARAMETER_TIMESTAMP_NAME, '2025-01-01'],
|
|
20
|
-
[FromNow.
|
|
20
|
+
[FromNow.PARAMETER_BASE_NAME, '2024-04-25'],
|
|
21
21
|
]),
|
|
22
22
|
);
|
|
23
23
|
|
|
@@ -35,7 +35,7 @@ describe('From Now', () => {
|
|
|
35
35
|
).setArguments(
|
|
36
36
|
new Map<string, any>([
|
|
37
37
|
[AbstractDateFunction.PARAMETER_TIMESTAMP_NAME, '2025-01-01'],
|
|
38
|
-
[FromNow.
|
|
38
|
+
[FromNow.PARAMETER_BASE_NAME, '2023-04-25'],
|
|
39
39
|
[FromNow.PARAMETER_UNIT_NAME, ['MONTHS', 'DAYS']],
|
|
40
40
|
[FromNow.PARAMETER_FORMAT_NAME, 'SHORT'],
|
|
41
41
|
]),
|
|
@@ -55,7 +55,7 @@ describe('From Now', () => {
|
|
|
55
55
|
).setArguments(
|
|
56
56
|
new Map<string, any>([
|
|
57
57
|
[AbstractDateFunction.PARAMETER_TIMESTAMP_NAME, '2025-01-01'],
|
|
58
|
-
[FromNow.
|
|
58
|
+
[FromNow.PARAMETER_BASE_NAME, '2023-04-25'],
|
|
59
59
|
[FromNow.PARAMETER_UNIT_NAME, ['DAYS']],
|
|
60
60
|
[FromNow.PARAMETER_FORMAT_NAME, 'LONG'],
|
|
61
61
|
[FromNow.PARAMETER_LOCALE_NAME, 'fr'],
|
|
@@ -30,7 +30,7 @@ describe('LastFirstOf', () => {
|
|
|
30
30
|
|
|
31
31
|
expect(
|
|
32
32
|
result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_TIMESTAMP_NAME),
|
|
33
|
-
).toBe('2024-01-
|
|
33
|
+
).toBe('2024-01-03T10:00:00.000Z');
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
test('should return the first timestamp', async () => {
|
|
@@ -49,7 +49,7 @@ describe('LastFirstOf', () => {
|
|
|
49
49
|
|
|
50
50
|
expect(
|
|
51
51
|
result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_TIMESTAMP_NAME),
|
|
52
|
-
).toBe('2024-01-
|
|
52
|
+
).toBe('2024-01-02T00:00:00.000Z');
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
test('should throw an error if no timestamps are provided', async () => {
|
|
@@ -21,9 +21,9 @@ describe('SetTimeZone', () => {
|
|
|
21
21
|
|
|
22
22
|
const result = await setTimeZone.execute(fep);
|
|
23
23
|
|
|
24
|
-
expect(
|
|
25
|
-
|
|
26
|
-
);
|
|
24
|
+
expect(
|
|
25
|
+
result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_TIMESTAMP_NAME),
|
|
26
|
+
).toBe('2024-01-01T09:00:00.000+09:00');
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
test('shoud set the time zone with offset', async () => {
|
|
@@ -41,8 +41,8 @@ describe('SetTimeZone', () => {
|
|
|
41
41
|
|
|
42
42
|
const result = await setTimeZone.execute(fep);
|
|
43
43
|
|
|
44
|
-
expect(
|
|
45
|
-
|
|
46
|
-
);
|
|
44
|
+
expect(
|
|
45
|
+
result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_TIMESTAMP_NAME),
|
|
46
|
+
).toBe('2024-01-01T05:30:00.000+05:30');
|
|
47
47
|
});
|
|
48
48
|
});
|
|
@@ -20,7 +20,7 @@ describe('StartEndOf', () => {
|
|
|
20
20
|
AbstractDateFunction.PARAMETER_TIMESTAMP_NAME,
|
|
21
21
|
'2023-12-31T22:00:00.000Z',
|
|
22
22
|
AbstractDateFunction.PARAMETER_UNIT_NAME,
|
|
23
|
-
'
|
|
23
|
+
'YEARS',
|
|
24
24
|
),
|
|
25
25
|
);
|
|
26
26
|
|
|
@@ -28,7 +28,7 @@ describe('StartEndOf', () => {
|
|
|
28
28
|
|
|
29
29
|
expect(
|
|
30
30
|
result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_TIMESTAMP_NAME),
|
|
31
|
-
).toBe('
|
|
31
|
+
).toBe('2023-01-01T00:00:00.000Z');
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
test('should return the end of the year', async () => {
|
|
@@ -40,7 +40,7 @@ describe('StartEndOf', () => {
|
|
|
40
40
|
AbstractDateFunction.PARAMETER_TIMESTAMP_NAME,
|
|
41
41
|
'2023-12-31T22:00:00.000Z',
|
|
42
42
|
AbstractDateFunction.PARAMETER_UNIT_NAME,
|
|
43
|
-
'
|
|
43
|
+
'YEARS',
|
|
44
44
|
),
|
|
45
45
|
);
|
|
46
46
|
|
|
@@ -48,6 +48,46 @@ describe('StartEndOf', () => {
|
|
|
48
48
|
|
|
49
49
|
expect(
|
|
50
50
|
result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_TIMESTAMP_NAME),
|
|
51
|
-
).toBe('
|
|
51
|
+
).toBe('2023-12-31T23:59:59.999Z');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('should return the end of day', async () => {
|
|
55
|
+
const fep = new FunctionExecutionParameters(
|
|
56
|
+
new KIRunFunctionRepository(),
|
|
57
|
+
new KIRunSchemaRepository(),
|
|
58
|
+
).setArguments(
|
|
59
|
+
MapUtil.of(
|
|
60
|
+
AbstractDateFunction.PARAMETER_TIMESTAMP_NAME,
|
|
61
|
+
'2023-12-31T22:00:00.000Z',
|
|
62
|
+
AbstractDateFunction.PARAMETER_UNIT_NAME,
|
|
63
|
+
'DAYS',
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const result = await endOf.execute(fep);
|
|
68
|
+
|
|
69
|
+
expect(
|
|
70
|
+
result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_TIMESTAMP_NAME),
|
|
71
|
+
).toBe('2023-12-31T23:59:59.999Z');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('should return the end of day in a different timezone', async () => {
|
|
75
|
+
const fep = new FunctionExecutionParameters(
|
|
76
|
+
new KIRunFunctionRepository(),
|
|
77
|
+
new KIRunSchemaRepository(),
|
|
78
|
+
).setArguments(
|
|
79
|
+
MapUtil.of(
|
|
80
|
+
AbstractDateFunction.PARAMETER_TIMESTAMP_NAME,
|
|
81
|
+
'2024-12-31T22:00:00.000-06:00',
|
|
82
|
+
AbstractDateFunction.PARAMETER_UNIT_NAME,
|
|
83
|
+
'DAYS',
|
|
84
|
+
),
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const result = await endOf.execute(fep);
|
|
88
|
+
|
|
89
|
+
expect(
|
|
90
|
+
result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_TIMESTAMP_NAME),
|
|
91
|
+
).toBe('2024-12-31T23:59:59.999-06:00');
|
|
52
92
|
});
|
|
53
93
|
});
|
|
@@ -14,7 +14,7 @@ describe('TimeAs', () => {
|
|
|
14
14
|
new KIRunFunctionRepository(),
|
|
15
15
|
new KIRunSchemaRepository(),
|
|
16
16
|
).setArguments(
|
|
17
|
-
MapUtil.of(TimeAs.PARAMETER_TIMESTAMP_NAME, '2024-11-10T10:10:10.100
|
|
17
|
+
MapUtil.of(TimeAs.PARAMETER_TIMESTAMP_NAME, '2024-11-10T10:10:10.100-05:00'),
|
|
18
18
|
);
|
|
19
19
|
const result = await timeAsArray.execute(fep);
|
|
20
20
|
expect(result.allResults()[0].getResult().get(TimeAs.EVENT_TIME_ARRAY_NAME)).toEqual([
|
|
@@ -45,4 +45,22 @@ describe('ToDateString', () => {
|
|
|
45
45
|
.get(AbstractDateFunction.EVENT_RESULT_NAME);
|
|
46
46
|
expect(result).toBe('1 janvier 2024');
|
|
47
47
|
});
|
|
48
|
+
|
|
49
|
+
test('should return the date string in the given format and no locale', async () => {
|
|
50
|
+
const fep = new FunctionExecutionParameters(
|
|
51
|
+
new KIRunFunctionRepository(),
|
|
52
|
+
new KIRunSchemaRepository(),
|
|
53
|
+
).setArguments(
|
|
54
|
+
new Map([
|
|
55
|
+
[ToDateString.PARAMETER_TIMESTAMP_NAME, '2024-01-01T00:00:00.000+05:30'],
|
|
56
|
+
[ToDateString.PARAMETER_FORMAT_NAME, 'DDD'],
|
|
57
|
+
]),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const result = await (await new ToDateString().execute(fep))
|
|
61
|
+
.allResults()[0]
|
|
62
|
+
.getResult()
|
|
63
|
+
.get(AbstractDateFunction.EVENT_RESULT_NAME);
|
|
64
|
+
expect(result).toBe('1 January 2024');
|
|
65
|
+
});
|
|
48
66
|
});
|