@fincity/kirun-js 2.7.0 → 2.8.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.
Files changed (100) hide show
  1. package/__tests__/engine/function/system/WaitTest.ts +1 -1
  2. package/__tests__/engine/function/system/array/AddFirstTest.ts +2 -6
  3. package/__tests__/engine/function/system/array/IndexOfTest.ts +8 -13
  4. package/__tests__/engine/function/system/array/LastIndexOfTest.ts +9 -28
  5. package/__tests__/engine/function/system/date/AddSubtractTimeTest.ts +93 -0
  6. package/__tests__/engine/function/system/date/DateFunctionRepositoryTest.ts +96 -0
  7. package/__tests__/engine/function/system/date/DifferenceTest.ts +93 -0
  8. package/__tests__/engine/function/system/date/EpochToTimestampTest.ts +133 -0
  9. package/__tests__/engine/function/system/date/FromDateStringTest.ts +51 -0
  10. package/__tests__/engine/function/system/date/FromNowTest.ts +71 -0
  11. package/__tests__/engine/function/system/date/GetCurrentTimeStampTest.ts +19 -27
  12. package/__tests__/engine/function/system/date/GetNamesTest.ts +105 -0
  13. package/__tests__/engine/function/system/date/IsBetweenTest.ts +53 -0
  14. package/__tests__/engine/function/system/date/IsValidISODateTest.ts +42 -54
  15. package/__tests__/engine/function/system/date/LastFirstOfTest.ts +64 -0
  16. package/__tests__/engine/function/system/date/SetTimeZoneTest.ts +48 -0
  17. package/__tests__/engine/function/system/date/StartEndOfTest.ts +53 -0
  18. package/__tests__/engine/function/system/date/TimeAsTest.ts +24 -0
  19. package/__tests__/engine/function/system/date/TimestampToEpochTest.ts +45 -0
  20. package/__tests__/engine/function/system/date/ToDateStringTest.ts +48 -0
  21. package/__tests__/engine/function/system/math/RandomFloatTest.ts +21 -22
  22. package/__tests__/engine/function/system/math/RandomIntTest.ts +5 -4
  23. package/__tests__/engine/repository/RepositoryFilterTest.ts +4 -1
  24. package/__tests__/engine/runtime/expression/ExpressionEqualityTest.ts +76 -0
  25. package/dist/index.js +1 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/module.js +1 -1
  28. package/dist/module.js.map +1 -1
  29. package/dist/types.d.ts +14 -13
  30. package/dist/types.d.ts.map +1 -1
  31. package/generator/generateValidationCSV.ts +51 -42
  32. package/generator/validation-js.csv +0 -0
  33. package/package.json +9 -7
  34. package/src/engine/function/AbstractFunction.ts +1 -1
  35. package/src/engine/function/system/Print.ts +19 -5
  36. package/src/engine/function/system/Wait.ts +1 -1
  37. package/src/engine/function/system/array/AbstractArrayFunction.ts +3 -3
  38. package/src/engine/function/system/array/Fill.ts +1 -1
  39. package/src/engine/function/system/array/Frequency.ts +0 -1
  40. package/src/engine/function/system/array/IndexOf.ts +4 -4
  41. package/src/engine/function/system/array/LastIndexOf.ts +3 -3
  42. package/src/engine/function/system/array/Rotate.ts +1 -1
  43. package/src/engine/function/system/array/Shuffle.ts +1 -1
  44. package/src/engine/function/system/array/Sort.ts +1 -1
  45. package/src/engine/function/system/date/AbstractDateFunction.ts +229 -111
  46. package/src/engine/function/system/date/AddSubtractTime.ts +99 -0
  47. package/src/engine/function/system/date/DateFunctionRepository.ts +228 -122
  48. package/src/engine/function/system/date/EpochToTimestamp.ts +75 -0
  49. package/src/engine/function/system/date/FromDateString.ts +44 -0
  50. package/src/engine/function/system/date/FromNow.ts +77 -0
  51. package/src/engine/function/system/date/GetCurrent.ts +20 -0
  52. package/src/engine/function/system/date/GetNames.ts +74 -0
  53. package/src/engine/function/system/date/IsBetween.ts +62 -0
  54. package/src/engine/function/system/date/IsValidISODate.ts +54 -40
  55. package/src/engine/function/system/date/LastFirstOf.ts +72 -0
  56. package/src/engine/function/system/date/SetTimeZone.ts +43 -0
  57. package/src/engine/function/system/date/StartEndOf.ts +44 -0
  58. package/src/engine/function/system/date/TimeAs.ts +64 -0
  59. package/src/engine/function/system/date/TimestampToEpoch.ts +54 -0
  60. package/src/engine/function/system/date/ToDateString.ts +49 -0
  61. package/src/engine/function/system/date/common.ts +9 -0
  62. package/src/engine/function/system/math/MathFunctionRepository.ts +43 -4
  63. package/src/engine/function/system/math/RandomAny.ts +57 -0
  64. package/src/engine/function/system/object/ObjectConvert.ts +45 -19
  65. package/src/engine/function/system/object/ObjectFunctionRepository.ts +2 -1
  66. package/src/engine/function/system/string/AbstractStringFunction.ts +42 -82
  67. package/src/engine/function/system/string/StringFunctionRepository.ts +39 -20
  68. package/src/engine/json/schema/SchemaUtil.ts +1 -1
  69. package/src/engine/repository/KIRunSchemaRepository.ts +57 -3
  70. package/src/engine/util/string/StringUtil.ts +12 -0
  71. package/tsconfig.json +1 -2
  72. package/__tests__/engine/function/system/date/AddTimeTest.ts +0 -115
  73. package/__tests__/engine/function/system/date/DateToEpochTest.ts +0 -74
  74. package/__tests__/engine/function/system/date/DifferenceOfTimestampsTest.ts +0 -53
  75. package/__tests__/engine/function/system/date/EpochToDateTest.ts +0 -105
  76. package/__tests__/engine/function/system/date/GetDateTest.ts +0 -85
  77. package/__tests__/engine/function/system/date/GetDayTest.ts +0 -85
  78. package/__tests__/engine/function/system/date/GetFullYearTest.ts +0 -85
  79. package/__tests__/engine/function/system/date/GetHoursTest.ts +0 -85
  80. package/__tests__/engine/function/system/date/GetMilliSecondsTest.ts +0 -85
  81. package/__tests__/engine/function/system/date/GetMinutesTest.ts +0 -85
  82. package/__tests__/engine/function/system/date/GetMonthTest.ts +0 -85
  83. package/__tests__/engine/function/system/date/GetSecondsTest.ts +0 -85
  84. package/__tests__/engine/function/system/date/GetTimeAsArrayTest.ts +0 -59
  85. package/__tests__/engine/function/system/date/GetTimeAsObjectTest.ts +0 -83
  86. package/__tests__/engine/function/system/date/GetTimeTest.ts +0 -86
  87. package/__tests__/engine/function/system/date/IsLeapYearTest.ts +0 -85
  88. package/__tests__/engine/function/system/date/MaximumTimestampTest.ts +0 -55
  89. package/__tests__/engine/function/system/date/MinimumTimestampTest.ts +0 -54
  90. package/__tests__/engine/function/system/date/SubtractTimeTest.ts +0 -95
  91. package/src/engine/function/system/date/DateToEpoch.ts +0 -39
  92. package/src/engine/function/system/date/DifferenceOfTimestamps.ts +0 -45
  93. package/src/engine/function/system/date/EpochToDate.ts +0 -76
  94. package/src/engine/function/system/date/GetCurrentTimeStamp.ts +0 -36
  95. package/src/engine/function/system/date/GetTimeAsArray.ts +0 -48
  96. package/src/engine/function/system/date/GetTimeAsObject.ts +0 -66
  97. package/src/engine/function/system/date/MaximumTimestamp.ts +0 -73
  98. package/src/engine/function/system/date/MinimumTimestamp.ts +0 -74
  99. package/src/engine/function/system/math/RandomFloat.ts +0 -56
  100. package/src/engine/function/system/math/RandomInt.ts +0 -56
@@ -0,0 +1,71 @@
1
+ import { Settings } from 'luxon';
2
+ import {
3
+ FunctionExecutionParameters,
4
+ KIRunFunctionRepository,
5
+ KIRunSchemaRepository,
6
+ } from '../../../../../src';
7
+ import { AbstractDateFunction } from '../../../../../src/engine/function/system/date/AbstractDateFunction';
8
+ import { FromNow } from '../../../../../src/engine/function/system/date/FromNow';
9
+
10
+ Settings.defaultZone = 'Asia/Kolkata';
11
+
12
+ describe('From Now', () => {
13
+ test('should return the relative date', async () => {
14
+ const fep = new FunctionExecutionParameters(
15
+ new KIRunFunctionRepository(),
16
+ new KIRunSchemaRepository(),
17
+ ).setArguments(
18
+ new Map([
19
+ [AbstractDateFunction.PARAMETER_TIMESTAMP_NAME, '2025-01-01'],
20
+ [FromNow.PARAMETER_FROM_NAME, '2024-04-25'],
21
+ ]),
22
+ );
23
+
24
+ const result = await new FromNow().execute(fep);
25
+
26
+ expect(result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(
27
+ 'in 8 months',
28
+ );
29
+ });
30
+
31
+ test('should return the relative date with units', async () => {
32
+ const fep = new FunctionExecutionParameters(
33
+ new KIRunFunctionRepository(),
34
+ new KIRunSchemaRepository(),
35
+ ).setArguments(
36
+ new Map<string, any>([
37
+ [AbstractDateFunction.PARAMETER_TIMESTAMP_NAME, '2025-01-01'],
38
+ [FromNow.PARAMETER_FROM_NAME, '2023-04-25'],
39
+ [FromNow.PARAMETER_UNIT_NAME, ['MONTHS', 'DAYS']],
40
+ [FromNow.PARAMETER_FORMAT_NAME, 'SHORT'],
41
+ ]),
42
+ );
43
+
44
+ const result = await new FromNow().execute(fep);
45
+
46
+ expect(result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(
47
+ 'in 20 mo',
48
+ );
49
+ });
50
+
51
+ test('should return the relative date with locale', async () => {
52
+ const fep = new FunctionExecutionParameters(
53
+ new KIRunFunctionRepository(),
54
+ new KIRunSchemaRepository(),
55
+ ).setArguments(
56
+ new Map<string, any>([
57
+ [AbstractDateFunction.PARAMETER_TIMESTAMP_NAME, '2025-01-01'],
58
+ [FromNow.PARAMETER_FROM_NAME, '2023-04-25'],
59
+ [FromNow.PARAMETER_UNIT_NAME, ['DAYS']],
60
+ [FromNow.PARAMETER_FORMAT_NAME, 'LONG'],
61
+ [FromNow.PARAMETER_LOCALE_NAME, 'fr'],
62
+ ]),
63
+ );
64
+
65
+ const result = await new FromNow().execute(fep);
66
+
67
+ expect(result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(
68
+ 'dans 617 jours',
69
+ );
70
+ });
71
+ });
@@ -1,35 +1,27 @@
1
- import { FunctionExecutionParameters } from '../../../../../src/engine/runtime/FunctionExecutionParameters';
2
- import { KIRunFunctionRepository, KIRunSchemaRepository } from '../../../../../src';
3
- import { GetCurrentTimeStamp } from '../../../../../src/engine/function/system/date/GetCurrentTimeStamp';
1
+ import { KIRunSchemaRepository, Namespaces } from '../../../../../src';
2
+ import { KIRunFunctionRepository } from '../../../../../src';
3
+ import { FunctionExecutionParameters } from '../../../../../src';
4
+ import { AbstractDateFunction } from '../../../../../src/engine/function/system/date/AbstractDateFunction';
5
+ import { DateFunctionRepository } from '../../../../../src/engine/function/system/date/DateFunctionRepository';
4
6
 
5
- const gcts: GetCurrentTimeStamp = new GetCurrentTimeStamp();
7
+ import { Settings } from 'luxon';
6
8
 
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
- })
9
+ Settings.defaultZone = 'Asia/Kolkata';
21
10
 
22
- describe('testing false case of GetCurrentTimeStamp', () => {
23
- test('checking with current time stamp', async () => {
24
- let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
11
+ describe('GetCurrentTimestamp', () => {
12
+ test('should return the current timestamp', async () => {
13
+ const fep = new FunctionExecutionParameters(
25
14
  new KIRunFunctionRepository(),
26
15
  new KIRunSchemaRepository(),
27
- ).setArguments(new Map([]));
16
+ ).setArguments(new Map());
28
17
 
29
- const d = new Date(Date.now()-1000000);
18
+ const result = await (await new DateFunctionRepository().find(
19
+ Namespaces.DATE,
20
+ 'GetCurrentTimestamp',
21
+ ))!.execute(fep);
30
22
 
31
- expect((await gcts.execute(fep)).allResults()[0].getResult().get('date')).not.toBe(
32
- d.toISOString()
33
- );
23
+ expect(
24
+ result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_TIMESTAMP_NAME),
25
+ ).toBeDefined();
34
26
  });
35
- })
27
+ });
@@ -0,0 +1,105 @@
1
+ import { KIRunFunctionRepository, KIRunSchemaRepository, MapUtil } from '../../../../../src';
2
+ import { DateFunctionRepository } from '../../../../../src/engine/function/system/date/DateFunctionRepository';
3
+ import { GetNames } from '../../../../../src/engine/function/system/date/GetNames';
4
+ import { FunctionExecutionParameters } from '../../../../../src/engine/runtime/FunctionExecutionParameters';
5
+
6
+ const getNames = new GetNames();
7
+
8
+ describe('GetNames', () => {
9
+ test('should return the names of the units', async () => {
10
+ const fep = new FunctionExecutionParameters(
11
+ new KIRunFunctionRepository(),
12
+ new KIRunSchemaRepository(),
13
+ ).setArguments(MapUtil.of(GetNames.PARAMETER_UNIT_NAME, 'TIMEZONES'));
14
+
15
+ const result = (await getNames.execute(fep))
16
+ .allResults()[0]
17
+ .getResult()
18
+ .get(GetNames.EVENT_NAMES_NAME);
19
+
20
+ expect(result).toEqual(Intl.supportedValuesOf('timeZone'));
21
+ });
22
+
23
+ test('should return the names of the months', async () => {
24
+ const fep = new FunctionExecutionParameters(
25
+ new KIRunFunctionRepository(),
26
+ new KIRunSchemaRepository(),
27
+ ).setArguments(MapUtil.of(GetNames.PARAMETER_UNIT_NAME, 'MONTHS'));
28
+
29
+ const result = (await getNames.execute(fep))
30
+ .allResults()[0]
31
+ .getResult()
32
+ .get(GetNames.EVENT_NAMES_NAME);
33
+
34
+ expect(result).toEqual([
35
+ 'January',
36
+ 'February',
37
+ 'March',
38
+ 'April',
39
+ 'May',
40
+ 'June',
41
+ 'July',
42
+ 'August',
43
+ 'September',
44
+ 'October',
45
+ 'November',
46
+ 'December',
47
+ ]);
48
+ });
49
+
50
+ test('should return the names of the weekdays', async () => {
51
+ const fep = new FunctionExecutionParameters(
52
+ new KIRunFunctionRepository(),
53
+ new KIRunSchemaRepository(),
54
+ ).setArguments(MapUtil.of(GetNames.PARAMETER_UNIT_NAME, 'WEEKDAYS'));
55
+
56
+ const result = (await getNames.execute(fep))
57
+ .allResults()[0]
58
+ .getResult()
59
+ .get(GetNames.EVENT_NAMES_NAME);
60
+
61
+ expect(result).toEqual([
62
+ 'Monday',
63
+ 'Tuesday',
64
+ 'Wednesday',
65
+ 'Thursday',
66
+ 'Friday',
67
+ 'Saturday',
68
+ 'Sunday',
69
+ ]);
70
+ });
71
+
72
+ test('should return the names of months in french', async () => {
73
+ const fep = new FunctionExecutionParameters(
74
+ new KIRunFunctionRepository(),
75
+ new KIRunSchemaRepository(),
76
+ ).setArguments(
77
+ MapUtil.of(
78
+ GetNames.PARAMETER_UNIT_NAME,
79
+ 'MONTHS',
80
+ GetNames.PARAMETER_LOCALE_NAME,
81
+ 'fr',
82
+ ),
83
+ );
84
+
85
+ const result = (await getNames.execute(fep))
86
+ .allResults()[0]
87
+ .getResult()
88
+ .get(GetNames.EVENT_NAMES_NAME);
89
+
90
+ expect(result).toEqual([
91
+ 'janvier',
92
+ 'février',
93
+ 'mars',
94
+ 'avril',
95
+ 'mai',
96
+ 'juin',
97
+ 'juillet',
98
+ 'août',
99
+ 'septembre',
100
+ 'octobre',
101
+ 'novembre',
102
+ 'décembre',
103
+ ]);
104
+ });
105
+ });
@@ -0,0 +1,53 @@
1
+ import { IsBetween } from '../../../../../src/engine/function/system/date/IsBetween';
2
+ import { KIRunFunctionRepository } from '../../../../../src/engine/repository/KIRunFunctionRepository';
3
+ import { KIRunSchemaRepository } from '../../../../../src/engine/repository/KIRunSchemaRepository';
4
+ import { MapUtil } from '../../../../../src/engine/util/MapUtil';
5
+ import { FunctionExecutionParameters } from '../../../../../src/engine/runtime/FunctionExecutionParameters';
6
+
7
+ import { Settings } from 'luxon';
8
+
9
+ Settings.defaultZone = 'UTC+05:30';
10
+
11
+ const isBetween = new IsBetween();
12
+
13
+ describe('IsBetween', () => {
14
+ test('should return true if the check timestamp is between the start and end timestamps', async () => {
15
+ const fep = new FunctionExecutionParameters(
16
+ new KIRunFunctionRepository(),
17
+ new KIRunSchemaRepository(),
18
+ ).setArguments(
19
+ MapUtil.of(
20
+ IsBetween.PARAMETER_START_TIMESTAMP_NAME,
21
+ '2024-01-01T00:00:00.000Z',
22
+ IsBetween.PARAMETER_END_TIMESTAMP_NAME,
23
+ '2024-01-02T00:00:00.000Z',
24
+ IsBetween.PARAMETER_CHECK_TIMESTAMP_NAME,
25
+ '2024-01-01T12:00:00.000Z',
26
+ ),
27
+ );
28
+
29
+ const result = await isBetween.execute(fep);
30
+
31
+ expect(result.allResults()[0].getResult().get(IsBetween.EVENT_RESULT_NAME)).toBe(true);
32
+ });
33
+
34
+ test('should return false if the check timestamp is not between the start and end timestamps', async () => {
35
+ const fep = new FunctionExecutionParameters(
36
+ new KIRunFunctionRepository(),
37
+ new KIRunSchemaRepository(),
38
+ ).setArguments(
39
+ MapUtil.of(
40
+ IsBetween.PARAMETER_START_TIMESTAMP_NAME,
41
+ '2024-01-01T00:00:00.000Z',
42
+ IsBetween.PARAMETER_END_TIMESTAMP_NAME,
43
+ '2024-01-02T00:00:00.000Z',
44
+ IsBetween.PARAMETER_CHECK_TIMESTAMP_NAME,
45
+ '2024-01-03T00:00:00.000Z',
46
+ ),
47
+ );
48
+
49
+ const result = await isBetween.execute(fep);
50
+
51
+ expect(result.allResults()[0].getResult().get(IsBetween.EVENT_RESULT_NAME)).toBe(false);
52
+ });
53
+ });
@@ -1,79 +1,67 @@
1
- import { FunctionExecutionParameters, KIRunFunctionRepository, KIRunSchemaRepository } from "../../../../../src";
2
- import { IsValidISODate } from "../../../../../src/engine/function/system/date/IsValidISODate";
1
+ import {
2
+ FunctionExecutionParameters,
3
+ KIRunFunctionRepository,
4
+ KIRunSchemaRepository,
5
+ } from '../../../../../src';
6
+ import { AbstractDateFunction } from '../../../../../src/engine/function/system/date/AbstractDateFunction';
7
+ import { IsValidISODate } from '../../../../../src/engine/function/system/date/IsValidISODate';
3
8
 
9
+ import { Settings } from 'luxon';
4
10
 
5
- const validIso: IsValidISODate = new IsValidISODate();
11
+ Settings.defaultZone = 'Asia/Kolkata';
6
12
 
7
- describe('checking the validity for not string types ',() => {
13
+ const isValidISODate = new IsValidISODate();
8
14
 
9
- let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
10
- new KIRunFunctionRepository(),
11
- new KIRunSchemaRepository(),
12
- );
13
-
14
- test('number test' , async () => {
15
-
16
- fep.setArguments(new Map([['isoDate',1234]]))
17
- await expect( validIso.execute(fep)).rejects.toThrow();
18
-
19
- });
20
-
21
- test('boolean test' , async () => {
22
-
23
- fep.setArguments(new Map([['isoDate',true]]))
24
- await expect(validIso.execute(fep)).rejects.toThrow();
25
-
26
- })
27
- })
28
-
29
- describe('checking validity for string date types' , () => {
30
-
31
- test('Date1', async () => {
32
- let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
33
- new KIRunFunctionRepository(),
34
- new KIRunSchemaRepository(),
35
- ).setArguments(new Map([['isoDate', "aws"]]));
36
-
37
- expect((await validIso.execute(fep)).allResults()[0].getResult().get('output')).toBeFalsy();
38
- });
39
- });
40
-
41
- describe('checking validity', () => {
42
-
43
- test('Date1', async () => {
15
+ describe('IsValidISODate', () => {
16
+ it('should return true for a valid ISO date', async () => {
44
17
  let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
45
18
  new KIRunFunctionRepository(),
46
19
  new KIRunSchemaRepository(),
47
- ).setArguments(new Map([['isoDate', "2023-10-04T11:45:38.939ss"]]));
48
-
49
- expect((await validIso.execute(fep)).allResults()[0].getResult().get('output')).toBeFalsy();
20
+ ).setArguments(
21
+ new Map([[AbstractDateFunction.PARAMETER_TIMESTAMP_NAME, '2024-01-01T00:00:00.000Z']]),
22
+ );
23
+
24
+ const result = await isValidISODate.execute(fep);
25
+ expect(result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(
26
+ true,
27
+ );
50
28
  });
51
29
 
52
- test('Date2', async () => {
30
+ it('should return false for an invalid ISO date', async () => {
53
31
  let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
54
32
  new KIRunFunctionRepository(),
55
33
  new KIRunSchemaRepository(),
56
- ).setArguments(new Map([['isoDate', "2023-10-04T11:45:38.939Z"]]));
34
+ ).setArguments(new Map([[AbstractDateFunction.PARAMETER_TIMESTAMP_NAME, 'invalid']]));
57
35
 
58
- expect((await validIso.execute(fep)).allResults()[0].getResult().get('output')).toBeTruthy();
36
+ const result = await isValidISODate.execute(fep);
37
+ expect(result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(
38
+ false,
39
+ );
59
40
  });
60
41
 
61
- test('Date3', async () => {
42
+ it('should return false for an invalid ISO date', async () => {
62
43
  let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
63
44
  new KIRunFunctionRepository(),
64
45
  new KIRunSchemaRepository(),
65
- ).setArguments(new Map([['isoDate', "2023-10-10T10:02:54.959Z"]]));
46
+ ).setArguments(new Map([[AbstractDateFunction.PARAMETER_TIMESTAMP_NAME, '2024-02-31']]));
66
47
 
67
- expect((await validIso.execute(fep)).allResults()[0].getResult().get('output')).toBeTruthy();
48
+ const result = await isValidISODate.execute(fep);
49
+ expect(result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(
50
+ false,
51
+ );
68
52
  });
69
53
 
70
- test('Date4', async () => {
54
+ it('should return false for an invalid leap year ISO date', async () => {
71
55
  let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
72
56
  new KIRunFunctionRepository(),
73
57
  new KIRunSchemaRepository(),
74
- ).setArguments(new Map([['isoDate', "2023-10-10T10:02:54.959-12:12"]]));
75
-
76
- expect((await validIso.execute(fep)).allResults()[0].getResult().get('output')).toBeTruthy();
58
+ ).setArguments(
59
+ new Map([[AbstractDateFunction.PARAMETER_TIMESTAMP_NAME, '2022-02-29T00:00:00.000Z']]),
60
+ );
61
+
62
+ const result = await isValidISODate.execute(fep);
63
+ expect(result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(
64
+ false,
65
+ );
77
66
  });
78
-
79
- })
67
+ });
@@ -0,0 +1,64 @@
1
+ import {
2
+ FunctionExecutionParameters,
3
+ KIRunSchemaRepository,
4
+ KIRunFunctionRepository,
5
+ MapUtil,
6
+ } from '../../../../../src';
7
+ import { AbstractDateFunction } from '../../../../../src/engine/function/system/date/AbstractDateFunction';
8
+ import { LastFirstOf } from '../../../../../src/engine/function/system/date/LastFirstOf';
9
+ import { Settings } from 'luxon';
10
+
11
+ Settings.defaultZone = 'UTC+05:30';
12
+
13
+ const lastOf = new LastFirstOf(true);
14
+ const firstOf = new LastFirstOf(false);
15
+
16
+ describe('LastFirstOf', () => {
17
+ test('should return the last timestamp', async () => {
18
+ const fep = new FunctionExecutionParameters(
19
+ new KIRunFunctionRepository(),
20
+ new KIRunSchemaRepository(),
21
+ ).setArguments(
22
+ MapUtil.of(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME, [
23
+ '2024-01-03T05:50:00.000+05:30',
24
+ '2024-01-02T00:00:00.000Z',
25
+ '2024-01-03T10:00:00.000Z',
26
+ ]),
27
+ );
28
+
29
+ const result = await lastOf.execute(fep);
30
+
31
+ expect(
32
+ result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_TIMESTAMP_NAME),
33
+ ).toBe('2024-01-03T15:30:00.000+05:30');
34
+ });
35
+
36
+ test('should return the first timestamp', async () => {
37
+ const fep = new FunctionExecutionParameters(
38
+ new KIRunFunctionRepository(),
39
+ new KIRunSchemaRepository(),
40
+ ).setArguments(
41
+ MapUtil.of(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME, [
42
+ '2024-01-03T05:50:00.000+05:30',
43
+ '2024-01-02T00:00:00.000Z',
44
+ '2024-01-03T10:00:00.000Z',
45
+ ]),
46
+ );
47
+
48
+ const result = await firstOf.execute(fep);
49
+
50
+ expect(
51
+ result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_TIMESTAMP_NAME),
52
+ ).toBe('2024-01-02T05:30:00.000+05:30');
53
+ });
54
+
55
+ test('should throw an error if no timestamps are provided', async () => {
56
+ const fep = new FunctionExecutionParameters(
57
+ new KIRunFunctionRepository(),
58
+ new KIRunSchemaRepository(),
59
+ ).setArguments(MapUtil.of(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME, []));
60
+
61
+ await expect(lastOf.execute(fep)).rejects.toThrow('No timestamps provided');
62
+ await expect(firstOf.execute(fep)).rejects.toThrow('No timestamps provided');
63
+ });
64
+ });
@@ -0,0 +1,48 @@
1
+ import { KIRunFunctionRepository, MapUtil, KIRunSchemaRepository } from '../../../../../src';
2
+ import { AbstractDateFunction } from '../../../../../src/engine/function/system/date/AbstractDateFunction';
3
+ import { SetTimeZone } from '../../../../../src/engine/function/system/date/SetTimeZone';
4
+ import { FunctionExecutionParameters } from '../../../../../src/engine/runtime/FunctionExecutionParameters';
5
+
6
+ const setTimeZone = new SetTimeZone();
7
+
8
+ describe('SetTimeZone', () => {
9
+ test('should set the time zone', async () => {
10
+ const fep = new FunctionExecutionParameters(
11
+ new KIRunFunctionRepository(),
12
+ new KIRunSchemaRepository(),
13
+ ).setArguments(
14
+ MapUtil.of(
15
+ AbstractDateFunction.PARAMETER_TIMESTAMP_NAME,
16
+ '2024-01-01T00:00:00.000Z',
17
+ SetTimeZone.PARAMETER_TIMEZONE_NAME,
18
+ 'Asia/Tokyo',
19
+ ),
20
+ );
21
+
22
+ const result = await setTimeZone.execute(fep);
23
+
24
+ expect(result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(
25
+ '2024-01-01T09:00:00.000+09:00',
26
+ );
27
+ });
28
+
29
+ test('shoud set the time zone with offset', async () => {
30
+ const fep = new FunctionExecutionParameters(
31
+ new KIRunFunctionRepository(),
32
+ new KIRunSchemaRepository(),
33
+ ).setArguments(
34
+ MapUtil.of(
35
+ AbstractDateFunction.PARAMETER_TIMESTAMP_NAME,
36
+ '2024-01-01T00:00:00.000Z',
37
+ SetTimeZone.PARAMETER_TIMEZONE_NAME,
38
+ 'UTC+05:30',
39
+ ),
40
+ );
41
+
42
+ const result = await setTimeZone.execute(fep);
43
+
44
+ expect(result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(
45
+ '2024-01-01T05:30:00.000+05:30',
46
+ );
47
+ });
48
+ });
@@ -0,0 +1,53 @@
1
+ import { KIRunSchemaRepository } from '../../../../../src/engine/repository/KIRunSchemaRepository';
2
+ import { KIRunFunctionRepository } from '../../../../../src/engine/repository/KIRunFunctionRepository';
3
+ import { FunctionExecutionParameters, MapUtil } from '../../../../../src';
4
+ import { AbstractDateFunction } from '../../../../../src/engine/function/system/date/AbstractDateFunction';
5
+ import { StartEndOf } from '../../../../../src/engine/function/system/date/StartEndOf';
6
+ import { Settings } from 'luxon';
7
+
8
+ Settings.defaultZone = 'UTC+05:30';
9
+
10
+ const startOf = new StartEndOf(true);
11
+ const endOf = new StartEndOf(false);
12
+
13
+ describe('StartEndOf', () => {
14
+ test('should return the start of the year', async () => {
15
+ const fep = new FunctionExecutionParameters(
16
+ new KIRunFunctionRepository(),
17
+ new KIRunSchemaRepository(),
18
+ ).setArguments(
19
+ MapUtil.of(
20
+ AbstractDateFunction.PARAMETER_TIMESTAMP_NAME,
21
+ '2023-12-31T22:00:00.000Z',
22
+ AbstractDateFunction.PARAMETER_UNIT_NAME,
23
+ 'YEAR',
24
+ ),
25
+ );
26
+
27
+ const result = await startOf.execute(fep);
28
+
29
+ expect(
30
+ result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_TIMESTAMP_NAME),
31
+ ).toBe('2024-01-01T00:00:00.000+05:30');
32
+ });
33
+
34
+ test('should return the end of the year', async () => {
35
+ const fep = new FunctionExecutionParameters(
36
+ new KIRunFunctionRepository(),
37
+ new KIRunSchemaRepository(),
38
+ ).setArguments(
39
+ MapUtil.of(
40
+ AbstractDateFunction.PARAMETER_TIMESTAMP_NAME,
41
+ '2023-12-31T22:00:00.000Z',
42
+ AbstractDateFunction.PARAMETER_UNIT_NAME,
43
+ 'YEAR',
44
+ ),
45
+ );
46
+
47
+ const result = await endOf.execute(fep);
48
+
49
+ expect(
50
+ result.allResults()[0].getResult().get(AbstractDateFunction.EVENT_TIMESTAMP_NAME),
51
+ ).toBe('2024-12-31T23:59:59.999+05:30');
52
+ });
53
+ });
@@ -0,0 +1,24 @@
1
+ import { MapUtil } from '../../../../../src/engine/util/MapUtil';
2
+ import { KIRunFunctionRepository, KIRunSchemaRepository } from '../../../../../src';
3
+ import { TimeAs } from '../../../../../src/engine/function/system/date/TimeAs';
4
+ import { FunctionExecutionParameters } from '../../../../../src/engine/runtime/FunctionExecutionParameters';
5
+ import { Settings } from 'luxon';
6
+ const timeAsArray = new TimeAs(true);
7
+ const timeAsObject = new TimeAs(false);
8
+
9
+ Settings.defaultZone = 'UTC+05:30';
10
+
11
+ describe('TimeAs', () => {
12
+ it('should return the time as an array', async () => {
13
+ const fep = new FunctionExecutionParameters(
14
+ new KIRunFunctionRepository(),
15
+ new KIRunSchemaRepository(),
16
+ ).setArguments(
17
+ MapUtil.of(TimeAs.PARAMETER_TIMESTAMP_NAME, '2024-11-10T10:10:10.100+05:30'),
18
+ );
19
+ const result = await timeAsArray.execute(fep);
20
+ expect(result.allResults()[0].getResult().get(TimeAs.EVENT_TIME_ARRAY_NAME)).toEqual([
21
+ 2024, 11, 10, 10, 10, 10, 100,
22
+ ]);
23
+ });
24
+ });
@@ -0,0 +1,45 @@
1
+ import { KIRunSchemaRepository } from '../../../../../src';
2
+ import { KIRunFunctionRepository } from '../../../../../src/engine/repository/KIRunFunctionRepository';
3
+ import { FunctionExecutionParameters } from '../../../../../src';
4
+ import { AbstractDateFunction } from '../../../../../src/engine/function/system/date/AbstractDateFunction';
5
+ import { TimestampToEpoch } from '../../../../../src/engine/function/system/date/TimestampToEpoch';
6
+
7
+ import { Settings } from 'luxon';
8
+
9
+ Settings.defaultZone = 'Asia/Kolkata';
10
+
11
+ describe('TimestampToEpoch', () => {
12
+ test('should return the epoch time in seconds', async () => {
13
+ const fep = new FunctionExecutionParameters(
14
+ new KIRunFunctionRepository(),
15
+ new KIRunSchemaRepository(),
16
+ ).setArguments(
17
+ new Map([
18
+ [AbstractDateFunction.PARAMETER_TIMESTAMP_NAME, '2024-01-01T00:00:00.000+05:30'],
19
+ ]),
20
+ );
21
+
22
+ const result = await (await new TimestampToEpoch('TimestampToEpoch', true).execute(fep))
23
+ .allResults()[0]
24
+ .getResult()
25
+ .get(AbstractDateFunction.EVENT_RESULT_NAME);
26
+ expect(result).toBe(1704047400);
27
+ });
28
+
29
+ test('should return the epoch time in milliseconds', async () => {
30
+ const fep = new FunctionExecutionParameters(
31
+ new KIRunFunctionRepository(),
32
+ new KIRunSchemaRepository(),
33
+ ).setArguments(
34
+ new Map([
35
+ [AbstractDateFunction.PARAMETER_TIMESTAMP_NAME, '2024-01-01T00:00:00.000+05:30'],
36
+ ]),
37
+ );
38
+
39
+ const result = await (await new TimestampToEpoch('TimestampToEpoch', false).execute(fep))
40
+ .allResults()[0]
41
+ .getResult()
42
+ .get(AbstractDateFunction.EVENT_RESULT_NAME);
43
+ expect(result).toBe(1704047400000);
44
+ });
45
+ });