@fincity/kirun-js 2.5.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 (124) 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/MathFunctionRepositoryTest.ts +2 -2
  22. package/__tests__/engine/function/system/math/MaximumTest.ts +3 -2
  23. package/__tests__/engine/function/system/math/MinimumTest.ts +18 -20
  24. package/__tests__/engine/function/system/math/RandomFloatTest.ts +21 -22
  25. package/__tests__/engine/function/system/math/RandomIntTest.ts +5 -4
  26. package/__tests__/engine/json/schema/covnertor/BooleanConvertorTest.ts +55 -0
  27. package/__tests__/engine/json/schema/covnertor/NullConvertorTest.ts +47 -0
  28. package/__tests__/engine/json/schema/covnertor/NumberConvertorTest.ts +154 -0
  29. package/__tests__/engine/json/schema/covnertor/StringConvertorTest.ts +56 -0
  30. package/__tests__/engine/json/schema/validator/AnyOfAllOfOneOfValidatorTest.ts +9 -7
  31. package/__tests__/engine/json/schema/validator/NotValidatorTest.ts +3 -3
  32. package/__tests__/engine/json/schema/validator/StringValidatorTest.ts +1 -9
  33. package/__tests__/engine/json/schema/validator/TypeValidatorTest.ts +290 -0
  34. package/__tests__/engine/repository/RepositoryFilterTest.ts +4 -1
  35. package/__tests__/engine/runtime/expression/ExpressionEqualityTest.ts +76 -0
  36. package/dist/index.js +1 -1
  37. package/dist/index.js.map +1 -1
  38. package/dist/module.js +1 -1
  39. package/dist/module.js.map +1 -1
  40. package/dist/types.d.ts +27 -20
  41. package/dist/types.d.ts.map +1 -1
  42. package/generator/generateValidationCSV.ts +52 -38
  43. package/generator/validation-js.csv +470 -166
  44. package/package.json +11 -6
  45. package/src/engine/function/AbstractFunction.ts +1 -1
  46. package/src/engine/function/system/Print.ts +19 -5
  47. package/src/engine/function/system/Wait.ts +1 -1
  48. package/src/engine/function/system/array/AbstractArrayFunction.ts +3 -3
  49. package/src/engine/function/system/array/Fill.ts +1 -1
  50. package/src/engine/function/system/array/Frequency.ts +0 -1
  51. package/src/engine/function/system/array/IndexOf.ts +4 -4
  52. package/src/engine/function/system/array/LastIndexOf.ts +3 -3
  53. package/src/engine/function/system/array/Rotate.ts +1 -1
  54. package/src/engine/function/system/array/Shuffle.ts +1 -1
  55. package/src/engine/function/system/array/Sort.ts +1 -1
  56. package/src/engine/function/system/date/AbstractDateFunction.ts +229 -111
  57. package/src/engine/function/system/date/AddSubtractTime.ts +99 -0
  58. package/src/engine/function/system/date/DateFunctionRepository.ts +228 -122
  59. package/src/engine/function/system/date/EpochToTimestamp.ts +75 -0
  60. package/src/engine/function/system/date/FromDateString.ts +44 -0
  61. package/src/engine/function/system/date/FromNow.ts +77 -0
  62. package/src/engine/function/system/date/GetCurrent.ts +20 -0
  63. package/src/engine/function/system/date/GetNames.ts +74 -0
  64. package/src/engine/function/system/date/IsBetween.ts +62 -0
  65. package/src/engine/function/system/date/IsValidISODate.ts +54 -40
  66. package/src/engine/function/system/date/LastFirstOf.ts +72 -0
  67. package/src/engine/function/system/date/SetTimeZone.ts +43 -0
  68. package/src/engine/function/system/date/StartEndOf.ts +44 -0
  69. package/src/engine/function/system/date/TimeAs.ts +64 -0
  70. package/src/engine/function/system/date/TimestampToEpoch.ts +54 -0
  71. package/src/engine/function/system/date/ToDateString.ts +49 -0
  72. package/src/engine/function/system/date/common.ts +9 -0
  73. package/src/engine/function/system/math/MathFunctionRepository.ts +43 -4
  74. package/src/engine/function/system/math/RandomAny.ts +57 -0
  75. package/src/engine/function/system/object/ObjectConvert.ts +99 -0
  76. package/src/engine/function/system/object/ObjectFunctionRepository.ts +2 -1
  77. package/src/engine/function/system/object/ObjectPutValue.ts +0 -2
  78. package/src/engine/function/system/string/AbstractStringFunction.ts +42 -82
  79. package/src/engine/function/system/string/StringFunctionRepository.ts +39 -20
  80. package/src/engine/json/schema/SchemaUtil.ts +1 -1
  81. package/src/engine/json/schema/convertor/BooleanConvertor.ts +76 -0
  82. package/src/engine/json/schema/convertor/NullConvertor.ts +31 -0
  83. package/src/engine/json/schema/convertor/NumberConvertor.ts +117 -0
  84. package/src/engine/json/schema/convertor/StringConvertor.ts +41 -0
  85. package/src/engine/json/schema/convertor/enums/ConversionMode.ts +11 -0
  86. package/src/engine/json/schema/convertor/exception/SchemaConversionException.ts +39 -0
  87. package/src/engine/json/schema/validator/AnyOfAllOfOneOfValidator.ts +96 -36
  88. package/src/engine/json/schema/validator/ArrayValidator.ts +15 -7
  89. package/src/engine/json/schema/validator/ObjectValidator.ts +24 -13
  90. package/src/engine/json/schema/validator/SchemaValidator.ts +74 -22
  91. package/src/engine/json/schema/validator/TypeValidator.ts +136 -23
  92. package/src/engine/repository/KIRunSchemaRepository.ts +57 -3
  93. package/src/engine/util/json/ConvertorUtil.ts +51 -0
  94. package/src/engine/util/json/ValidatorUtil.ts +29 -0
  95. package/src/engine/util/string/StringUtil.ts +12 -0
  96. package/__tests__/engine/function/system/date/AddTimeTest.ts +0 -115
  97. package/__tests__/engine/function/system/date/DateToEpochTest.ts +0 -74
  98. package/__tests__/engine/function/system/date/DifferenceOfTimestampsTest.ts +0 -53
  99. package/__tests__/engine/function/system/date/EpochToDateTest.ts +0 -105
  100. package/__tests__/engine/function/system/date/GetDateTest.ts +0 -85
  101. package/__tests__/engine/function/system/date/GetDayTest.ts +0 -85
  102. package/__tests__/engine/function/system/date/GetFullYearTest.ts +0 -85
  103. package/__tests__/engine/function/system/date/GetHoursTest.ts +0 -85
  104. package/__tests__/engine/function/system/date/GetMilliSecondsTest.ts +0 -85
  105. package/__tests__/engine/function/system/date/GetMinutesTest.ts +0 -85
  106. package/__tests__/engine/function/system/date/GetMonthTest.ts +0 -85
  107. package/__tests__/engine/function/system/date/GetSecondsTest.ts +0 -85
  108. package/__tests__/engine/function/system/date/GetTimeAsArrayTest.ts +0 -59
  109. package/__tests__/engine/function/system/date/GetTimeAsObjectTest.ts +0 -83
  110. package/__tests__/engine/function/system/date/GetTimeTest.ts +0 -86
  111. package/__tests__/engine/function/system/date/IsLeapYearTest.ts +0 -85
  112. package/__tests__/engine/function/system/date/MaximumTimestampTest.ts +0 -55
  113. package/__tests__/engine/function/system/date/MinimumTimestampTest.ts +0 -54
  114. package/__tests__/engine/function/system/date/SubtractTimeTest.ts +0 -95
  115. package/src/engine/function/system/date/DateToEpoch.ts +0 -39
  116. package/src/engine/function/system/date/DifferenceOfTimestamps.ts +0 -45
  117. package/src/engine/function/system/date/EpochToDate.ts +0 -76
  118. package/src/engine/function/system/date/GetCurrentTimeStamp.ts +0 -36
  119. package/src/engine/function/system/date/GetTimeAsArray.ts +0 -48
  120. package/src/engine/function/system/date/GetTimeAsObject.ts +0 -66
  121. package/src/engine/function/system/date/MaximumTimestamp.ts +0 -73
  122. package/src/engine/function/system/date/MinimumTimestamp.ts +0 -74
  123. package/src/engine/function/system/math/RandomFloat.ts +0 -56
  124. package/src/engine/function/system/math/RandomInt.ts +0 -56
@@ -0,0 +1,99 @@
1
+ import { DurationLikeObject } from 'luxon';
2
+ import { Schema } from '../../../json/schema/Schema';
3
+ import { EventResult } from '../../../model/EventResult';
4
+ import { FunctionOutput } from '../../../model/FunctionOutput';
5
+ import { Parameter } from '../../../model/Parameter';
6
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
7
+ import { MapUtil } from '../../../util/MapUtil';
8
+ import { AbstractDateFunction } from './AbstractDateFunction';
9
+ import { getDateTime } from './common';
10
+
11
+ export class AddSubtractTime extends AbstractDateFunction {
12
+ public static readonly PARAMETER_YEARS_NAME = 'years';
13
+ public static readonly PARAMETER_MONTHS_NAME = 'months';
14
+ public static readonly PARAMETER_DAYS_NAME = 'days';
15
+ public static readonly PARAMETER_HOURS_NAME = 'hours';
16
+ public static readonly PARAMETER_MINUTES_NAME = 'minutes';
17
+ public static readonly PARAMETER_SECONDS_NAME = 'seconds';
18
+ public static readonly PARAMETER_MILLISECONDS_NAME = 'milliseconds';
19
+
20
+ private readonly isAdd: boolean;
21
+
22
+ constructor(isAdd: boolean) {
23
+ super(
24
+ isAdd ? 'AddTime' : 'SubtractTime',
25
+ AbstractDateFunction.EVENT_TIMESTAMP,
26
+ AbstractDateFunction.PARAMETER_TIMESTAMP,
27
+ Parameter.of(
28
+ AddSubtractTime.PARAMETER_YEARS_NAME,
29
+ Schema.ofNumber(AddSubtractTime.PARAMETER_YEARS_NAME).setDefaultValue(0),
30
+ ),
31
+ Parameter.of(
32
+ AddSubtractTime.PARAMETER_MONTHS_NAME,
33
+ Schema.ofNumber(AddSubtractTime.PARAMETER_MONTHS_NAME).setDefaultValue(0),
34
+ ),
35
+ Parameter.of(
36
+ AddSubtractTime.PARAMETER_DAYS_NAME,
37
+ Schema.ofNumber(AddSubtractTime.PARAMETER_DAYS_NAME).setDefaultValue(0),
38
+ ),
39
+ Parameter.of(
40
+ AddSubtractTime.PARAMETER_HOURS_NAME,
41
+ Schema.ofNumber(AddSubtractTime.PARAMETER_HOURS_NAME).setDefaultValue(0),
42
+ ),
43
+ Parameter.of(
44
+ AddSubtractTime.PARAMETER_MINUTES_NAME,
45
+ Schema.ofNumber(AddSubtractTime.PARAMETER_MINUTES_NAME).setDefaultValue(0),
46
+ ),
47
+ Parameter.of(
48
+ AddSubtractTime.PARAMETER_SECONDS_NAME,
49
+ Schema.ofNumber(AddSubtractTime.PARAMETER_SECONDS_NAME).setDefaultValue(0),
50
+ ),
51
+ Parameter.of(
52
+ AddSubtractTime.PARAMETER_MILLISECONDS_NAME,
53
+ Schema.ofNumber(AddSubtractTime.PARAMETER_MILLISECONDS_NAME).setDefaultValue(0),
54
+ ),
55
+ );
56
+
57
+ this.isAdd = isAdd;
58
+ }
59
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
60
+ const timestamp = context
61
+ .getArguments()
62
+ ?.get(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME);
63
+
64
+ const dateTime = getDateTime(timestamp);
65
+ const years = context.getArguments()?.get(AddSubtractTime.PARAMETER_YEARS_NAME);
66
+ const months = context.getArguments()?.get(AddSubtractTime.PARAMETER_MONTHS_NAME);
67
+ const days = context.getArguments()?.get(AddSubtractTime.PARAMETER_DAYS_NAME);
68
+ const hours = context.getArguments()?.get(AddSubtractTime.PARAMETER_HOURS_NAME);
69
+ const minutes = context.getArguments()?.get(AddSubtractTime.PARAMETER_MINUTES_NAME);
70
+ const seconds = context.getArguments()?.get(AddSubtractTime.PARAMETER_SECONDS_NAME);
71
+ const milliseconds = context
72
+ .getArguments()
73
+ ?.get(AddSubtractTime.PARAMETER_MILLISECONDS_NAME);
74
+
75
+ const options = {
76
+ years,
77
+ months,
78
+ days,
79
+ hours,
80
+ minutes,
81
+ seconds,
82
+ milliseconds,
83
+ } as DurationLikeObject;
84
+
85
+ let newDateTime;
86
+
87
+ if (this.isAdd) {
88
+ newDateTime = dateTime.plus(options);
89
+ } else {
90
+ newDateTime = dateTime.minus(options);
91
+ }
92
+
93
+ return new FunctionOutput([
94
+ EventResult.outputOf(
95
+ MapUtil.of(AbstractDateFunction.EVENT_TIMESTAMP_NAME, newDateTime.toISO()),
96
+ ),
97
+ ]);
98
+ }
99
+ }
@@ -1,147 +1,254 @@
1
- import { Namespaces } from "../../../namespaces/Namespaces";
2
- import { Repository } from "../../../Repository";
3
- import { MapUtil } from "../../../util/MapUtil";
4
- import { AbstractDateFunction } from "./AbstractDateFunction";
1
+ import { Namespaces } from '../../../namespaces/Namespaces';
2
+ import { Event } from '../../../model/Event';
3
+ import { Repository } from '../../../Repository';
4
+ import { MapUtil } from '../../../util/MapUtil';
5
5
  import { Function } from '../../Function';
6
- import { KIRuntimeException } from "../../../exception/KIRuntimeException";
7
- import mapEntry from '../../../util/mapEntry';
8
- import { DateToEpoch } from "./DateToEpoch";
9
- import { DifferenceOfTimestamps } from "./DifferenceOfTimestamps";
10
- import { EpochToDate } from "./EpochToDate";
11
- import { GetCurrentTimeStamp } from "./GetCurrentTimeStamp";
12
- import { GetTimeAsArray } from "./GetTimeAsArray";
13
- import { GetTimeAsObject } from "./GetTimeAsObject";
14
- import { IsValidISODate } from "./IsValidISODate";
15
- import { MaximumTimestamp } from "./MaximumTimestamp";
16
- import { MinimumTimestamp } from "./MinimumTimestamp";
17
-
6
+ import { AbstractDateFunction } from './AbstractDateFunction';
7
+ import { AddSubtractTime } from './AddSubtractTime';
8
+ import { getDateTime } from './common';
9
+ import { EpochToTimestamp } from './EpochToTimestamp';
10
+ import { TimestampToEpoch } from './TimestampToEpoch';
11
+ import { ToDateString } from './ToDateString';
12
+ import { Schema } from '../../../json/schema/Schema';
13
+ import { DateTimeUnit, DurationUnits } from 'luxon';
14
+ import { SetTimeZone } from './SetTimeZone';
15
+ import { IsBetween } from './IsBetween';
16
+ import { LastFirstOf } from './LastFirstOf';
17
+ import { TimeAs } from './TimeAs';
18
+ import { StartEndOf } from './StartEndOf';
19
+ import { GetNames } from './GetNames';
20
+ import { IsValidISODate } from './IsValidISODate';
21
+ import { FromNow } from './FromNow';
22
+ import { FromDateString } from './FromDateString';
23
+ import { GetCurrentTimestamp } from './GetCurrent';
18
24
 
19
25
  export class DateFunctionRepository implements Repository<Function> {
20
-
21
26
  private static readonly repoMap: Map<string, Function> = MapUtil.ofArrayEntries(
27
+ ['EpochSecondsToTimestamp', new EpochToTimestamp('EpochSecondsToTimestamp', true)],
28
+ [
29
+ 'EpochMillisecondsToTimestamp',
30
+ new EpochToTimestamp('EpochMillisecondsToTimestamp', false),
31
+ ],
32
+ AbstractDateFunction.ofEntryTimestampAndIntegerOutput(
33
+ 'GetDay',
34
+ (isoTimestamp: string) => getDateTime(isoTimestamp).day,
35
+ ),
36
+ AbstractDateFunction.ofEntryTimestampAndIntegerOutput(
37
+ 'GetDayOfWeek',
38
+ (isoTimestamp: string) => getDateTime(isoTimestamp).weekday,
39
+ ),
40
+ AbstractDateFunction.ofEntryTimestampAndIntegerOutput(
41
+ 'GetMonth',
42
+ (isoTimestamp: string) => getDateTime(isoTimestamp).month,
43
+ ),
44
+ AbstractDateFunction.ofEntryTimestampAndIntegerOutput(
45
+ 'GetYear',
46
+ (isoTimestamp: string) => getDateTime(isoTimestamp).year,
47
+ ),
48
+ AbstractDateFunction.ofEntryTimestampAndIntegerOutput(
49
+ 'GetHours',
50
+ (isoTimestamp: string) => getDateTime(isoTimestamp).hour,
51
+ ),
52
+ AbstractDateFunction.ofEntryTimestampAndIntegerOutput(
53
+ 'GetMinutes',
54
+ (isoTimestamp: string) => getDateTime(isoTimestamp).minute,
55
+ ),
56
+ AbstractDateFunction.ofEntryTimestampAndIntegerOutput(
57
+ 'GetSeconds',
58
+ (isoTimestamp: string) => getDateTime(isoTimestamp).second,
59
+ ),
60
+ AbstractDateFunction.ofEntryTimestampAndIntegerOutput(
61
+ 'GetMilliseconds',
62
+ (isoTimestamp: string) => getDateTime(isoTimestamp).millisecond,
63
+ ),
64
+ AbstractDateFunction.ofEntryTimestampAndIntegerOutput(
65
+ 'GetDaysInMonth',
66
+ (isoTimestamp: string) => getDateTime(isoTimestamp).daysInMonth!,
67
+ ),
68
+ AbstractDateFunction.ofEntryTimestampAndIntegerOutput(
69
+ 'GetDaysInYear',
70
+ (isoTimestamp: string) => getDateTime(isoTimestamp).daysInYear!,
71
+ ),
72
+ ['TimestampToEpochSeconds', new TimestampToEpoch('TimestampToEpochSeconds', true)],
73
+ [
74
+ 'TimestampToEpochMilliseconds',
75
+ new TimestampToEpoch('TimestampToEpochMilliseconds', false),
76
+ ],
77
+ AbstractDateFunction.ofEntryTimestampAndStringOutput(
78
+ 'GetTimeZoneName',
79
+ (isoTimestamp: string) => getDateTime(isoTimestamp).zoneName!,
80
+ ),
81
+ AbstractDateFunction.ofEntryTimestampAndStringOutput(
82
+ 'GetTimeZoneOffsetLong',
83
+ (isoTimestamp: string) => getDateTime(isoTimestamp).offsetNameLong!,
84
+ ),
85
+ AbstractDateFunction.ofEntryTimestampAndStringOutput(
86
+ 'GetTimeZoneOffsetShort',
87
+ (isoTimestamp: string) => getDateTime(isoTimestamp).offsetNameShort!,
88
+ ),
89
+ AbstractDateFunction.ofEntryTimestampAndIntegerOutput(
90
+ 'GetTimeZoneOffset',
91
+ (isoTimestamp: string) => getDateTime(isoTimestamp).offset,
92
+ ),
93
+ ['ToDateString', new ToDateString()],
94
+ ['AddTime', new AddSubtractTime(true)],
95
+ ['SubtractTime', new AddSubtractTime(false)],
96
+ ['GetCurrentTimestamp', new GetCurrentTimestamp()],
22
97
 
23
- mapEntry(new DateToEpoch()),
24
- mapEntry(new EpochToDate()),
25
- mapEntry(new GetCurrentTimeStamp()),
26
- mapEntry(new DifferenceOfTimestamps()),
27
- mapEntry(new IsValidISODate()),
28
- mapEntry(new GetTimeAsArray()),
29
- mapEntry(new GetTimeAsObject()),
30
- mapEntry(new MaximumTimestamp()),
31
- mapEntry(new MinimumTimestamp()),
32
-
33
- AbstractDateFunction.ofEntryDateAndBooleanOutput("IsLeapYear", date => {
34
- const year = new Date(date).getUTCFullYear();
35
- return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0);
36
- }),
37
-
38
- AbstractDateFunction.ofEntryDateAndIntegerOutput("GetDate", date => new Date(date).getUTCDate()),
98
+ AbstractDateFunction.ofEntryTimestampTimestampAndTOutput<any>(
99
+ 'Difference',
100
+ new Event(
101
+ Event.OUTPUT,
102
+ MapUtil.of(
103
+ AbstractDateFunction.EVENT_RESULT_NAME,
104
+ Schema.ofRef(`${Namespaces.DATE}.Duration`),
105
+ ),
106
+ ),
107
+ (ts1: string, ts2: string, extraParams: any[]) => {
108
+ const dt1 = getDateTime(ts1);
109
+ const dt2 = getDateTime(ts2);
110
+ let units: DurationUnits | undefined = undefined;
111
+ if (extraParams?.[0]?.length) {
112
+ units = extraParams[0]
113
+ ?.filter((e: any) => !!e)
114
+ .map((e: string) => e.toLowerCase() as DateTimeUnit);
115
+ }
116
+ const duration = dt1.diff(dt2, units);
117
+ return duration.toObject();
118
+ },
119
+ AbstractDateFunction.PARAMETER_VARIABLE_UNIT,
120
+ ),
39
121
 
40
- AbstractDateFunction.ofEntryDateAndIntegerOutput("GetDay", date => new Date(date).getUTCDay()),
122
+ AbstractDateFunction.ofEntryTimestampIntegerAndTimestampOutput(
123
+ 'SetDay',
124
+ (isoTimestamp: string, day: number) => getDateTime(isoTimestamp).set({ day }).toISO()!,
125
+ ),
41
126
 
42
- AbstractDateFunction.ofEntryDateAndIntegerOutput("GetFullYear", date => new Date(date).getUTCFullYear()),
127
+ AbstractDateFunction.ofEntryTimestampIntegerAndTimestampOutput(
128
+ 'SetMonth',
129
+ (isoTimestamp: string, month: number) =>
130
+ getDateTime(isoTimestamp).set({ month }).toISO()!,
131
+ ),
43
132
 
44
- AbstractDateFunction.ofEntryDateAndIntegerOutput("GetMonth", date => new Date(date).getUTCMonth()),
133
+ AbstractDateFunction.ofEntryTimestampIntegerAndTimestampOutput(
134
+ 'SetYear',
135
+ (isoTimestamp: string, year: number) =>
136
+ getDateTime(isoTimestamp).set({ year }).toISO()!,
137
+ ),
45
138
 
46
- AbstractDateFunction.ofEntryDateAndIntegerOutput("GetHours", date => new Date(date).getUTCHours()),
139
+ AbstractDateFunction.ofEntryTimestampIntegerAndTimestampOutput(
140
+ 'SetHours',
141
+ (isoTimestamp: string, hour: number) =>
142
+ getDateTime(isoTimestamp).set({ hour }).toISO()!,
143
+ ),
47
144
 
48
- AbstractDateFunction.ofEntryDateAndIntegerOutput("GetMinutes", date => new Date(date).getUTCMinutes()),
145
+ AbstractDateFunction.ofEntryTimestampIntegerAndTimestampOutput(
146
+ 'SetMinutes',
147
+ (isoTimestamp: string, minute: number) =>
148
+ getDateTime(isoTimestamp).set({ minute }).toISO()!,
149
+ ),
49
150
 
50
- AbstractDateFunction.ofEntryDateAndIntegerOutput("GetSeconds", date => new Date(date).getUTCSeconds()),
151
+ AbstractDateFunction.ofEntryTimestampIntegerAndTimestampOutput(
152
+ 'SetSeconds',
153
+ (isoTimestamp: string, second: number) =>
154
+ getDateTime(isoTimestamp).set({ second }).toISO()!,
155
+ ),
51
156
 
52
- AbstractDateFunction.ofEntryDateAndIntegerOutput("GetMilliSeconds", date => new Date(date).getUTCMilliseconds()),
157
+ AbstractDateFunction.ofEntryTimestampIntegerAndTimestampOutput(
158
+ 'SetMilliseconds',
159
+ (isoTimestamp: string, millisecond: number) =>
160
+ getDateTime(isoTimestamp).set({ millisecond }).toISO()!,
161
+ ),
53
162
 
54
- AbstractDateFunction.ofEntryDateAndIntegerOutput("GetTime" , date => new Date(date).getTime()),
163
+ ['SetTimeZone', new SetTimeZone()],
55
164
 
56
- AbstractDateFunction.ofEntryDateWithIntegerUnitWithOutputName("AddTime",
57
- (date , value , unit) => this.changeAmountToUnit(date, unit, value, true)
165
+ AbstractDateFunction.ofEntryTimestampTimestampAndTOutput<boolean>(
166
+ 'IsBefore',
167
+ new Event(
168
+ Event.OUTPUT,
169
+ MapUtil.of(
170
+ AbstractDateFunction.EVENT_RESULT_NAME,
171
+ Schema.ofBoolean(AbstractDateFunction.EVENT_RESULT_NAME),
172
+ ),
173
+ ),
174
+ (t1: string, t2: string) => getDateTime(t1) < getDateTime(t2),
58
175
  ),
59
176
 
60
- AbstractDateFunction.ofEntryDateWithIntegerUnitWithOutputName("SubtractTime",
61
- (date , value , unit) => this.changeAmountToUnit(date, unit, value, false)
62
- )
63
- );
177
+ AbstractDateFunction.ofEntryTimestampTimestampAndTOutput<boolean>(
178
+ 'IsAfter',
179
+ new Event(
180
+ Event.OUTPUT,
181
+ MapUtil.of(
182
+ AbstractDateFunction.EVENT_RESULT_NAME,
183
+ Schema.ofBoolean(AbstractDateFunction.EVENT_RESULT_NAME),
184
+ ),
185
+ ),
186
+ (t1: string, t2: string) => getDateTime(t1) > getDateTime(t2),
187
+ ),
64
188
 
65
- private static readonly filterableNames = Array.from(
66
- DateFunctionRepository.repoMap.values(),
67
- ).map((e) => e.getSignature().getFullName());
189
+ AbstractDateFunction.ofEntryTimestampTimestampAndTOutput<boolean>(
190
+ 'IsSame',
191
+ new Event(
192
+ Event.OUTPUT,
193
+ MapUtil.of(
194
+ AbstractDateFunction.EVENT_RESULT_NAME,
195
+ Schema.ofBoolean(AbstractDateFunction.EVENT_RESULT_NAME),
196
+ ),
197
+ ),
198
+ (t1: string, t2: string) => getDateTime(t1) === getDateTime(t2),
199
+ ),
68
200
 
69
- private static changeAmountToUnit(inputDate: string , unit: string, value: number, isAdd: boolean): string{
70
-
71
- const amount = isAdd ? value : -1 * value;
72
-
73
- const date = this.getFullUTCDate(inputDate);
74
- const originalOffset = this.getTimezoneOffset(inputDate);
75
-
76
- switch(unit){
77
-
78
- case "MILLISECOND" : date.setMilliseconds(date.getMilliseconds() + amount);
79
- break;
80
- case "SECOND" : date.setSeconds(date.getSeconds() + amount);
81
- break;
82
- case "MINUTE" : date.setMinutes(date.getMinutes() + amount);
83
- break;
84
- case "HOUR" : date.setHours(date.getHours() + amount);
85
- break;
86
- case "DAY" : date.setDate(date.getDate() + amount);
87
- break;
88
- case "MONTH" : date.setMonth(date.getMonth() + amount);
89
- break;
90
- case "YEAR" : date.setFullYear(date.getFullYear() + amount);
91
- break;
92
- default :
93
- throw new KIRuntimeException("No such unit: " + unit)
201
+ AbstractDateFunction.ofEntryTimestampTimestampAndTOutput<boolean>(
202
+ 'IsSameOrBefore',
203
+ new Event(
204
+ Event.OUTPUT,
205
+ MapUtil.of(
206
+ AbstractDateFunction.EVENT_RESULT_NAME,
207
+ Schema.ofBoolean(AbstractDateFunction.EVENT_RESULT_NAME),
208
+ ),
209
+ ),
210
+ (t1: string, t2: string) => getDateTime(t1) <= getDateTime(t2),
211
+ ),
94
212
 
95
- }
213
+ AbstractDateFunction.ofEntryTimestampTimestampAndTOutput<boolean>(
214
+ 'IsSameOrAfter',
215
+ new Event(
216
+ Event.OUTPUT,
217
+ MapUtil.of(
218
+ AbstractDateFunction.EVENT_RESULT_NAME,
219
+ Schema.ofBoolean(AbstractDateFunction.EVENT_RESULT_NAME),
220
+ ),
221
+ ),
222
+ (t1: string, t2: string) => getDateTime(t1) >= getDateTime(t2),
223
+ ),
96
224
 
97
- return this.formatDate(date, originalOffset);
98
- }
99
-
100
- private static getTimezoneOffset(dateString: string): string {
101
- const lastChar = dateString.charAt(dateString.length - 1);
102
- if (lastChar === 'Z') return '+00:00';
103
-
104
- const offsetStart = dateString.indexOf('+') !== -1 ? dateString.lastIndexOf('+') : dateString.lastIndexOf('-');
105
- if (offsetStart === -1) return '+00:00';
106
-
107
- let offset = dateString.substring(offsetStart);
108
- if (offset.length === 3) {
109
- offset = offset.substring(0, 1) + '0' + offset.substring(1) + ':00';
110
- } else if (offset.length === 5) {
111
- offset = offset.substring(0, 3) + ':' + offset.substring(3);
112
- }
113
-
114
- return offset;
115
- }
225
+ AbstractDateFunction.ofEntryTimestampAndBooleanOutput(
226
+ 'IsInLeapYear',
227
+ (isoTimestamp: string) => getDateTime(isoTimestamp).isInLeapYear,
228
+ ),
116
229
 
117
- private static getFullUTCDate(inputDate:string): Date {
230
+ AbstractDateFunction.ofEntryTimestampAndBooleanOutput(
231
+ 'IsInDST',
232
+ (isoTimestamp: string) => getDateTime(isoTimestamp).isInDST,
233
+ ),
118
234
 
119
- if(inputDate.lastIndexOf('+') !== -1)
120
- inputDate = inputDate.substring(0, inputDate.lastIndexOf('+')) + 'Z';
121
- else if(inputDate.lastIndexOf('-') !== -1)
122
- inputDate = inputDate.substring(0, inputDate.lastIndexOf('-')) + 'Z';
235
+ ['IsBetween', new IsBetween()],
236
+ ['LastOf', new LastFirstOf(true)],
237
+ ['FirstOf', new LastFirstOf(false)],
238
+ ['StartOf', new StartEndOf(true)],
239
+ ['EndOf', new StartEndOf(false)],
240
+ ['TimeAsObject', new TimeAs(false)],
241
+ ['TimeAsArray', new TimeAs(true)],
242
+ ['GetNames', new GetNames()],
243
+ ['IsValidISODate', new IsValidISODate()],
244
+ ['FromNow', new FromNow()],
245
+ ['FromDateString', new FromDateString()],
246
+ );
123
247
 
124
- const date: Date = new Date(inputDate);
125
-
126
- return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1,
127
- date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(),
128
- date.getUTCSeconds(), date.getUTCMilliseconds()));
129
- }
248
+ private static readonly filterableNames = Array.from(
249
+ DateFunctionRepository.repoMap.values(),
250
+ ).map((e) => e.getSignature().getFullName());
130
251
 
131
- private static formatDate(date: Date, offset: string): string {
132
- const pad = (num: number) => num.toString().padStart(2, '0');
133
-
134
- const year = date.getUTCMonth() === 0 ? date.getUTCFullYear() - 1 : date.getUTCFullYear();
135
- const month = pad(date.getUTCMonth() === 0 ? 12 : date.getUTCMonth());
136
- const day = pad(date.getUTCDate());
137
- const hours = pad(date.getUTCHours());
138
- const minutes = pad(date.getUTCMinutes());
139
- const seconds = pad(date.getUTCSeconds());
140
- const milliseconds = pad(date.getUTCMilliseconds());
141
-
142
- return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}${offset}`;
143
- }
144
-
145
252
  find(namespace: string, name: string): Promise<Function | undefined> {
146
253
  if (namespace != Namespaces.DATE) {
147
254
  return Promise.resolve(undefined);
@@ -149,11 +256,10 @@ export class DateFunctionRepository implements Repository<Function> {
149
256
  return Promise.resolve(DateFunctionRepository.repoMap.get(name));
150
257
  }
151
258
  filter(name: string): Promise<string[]> {
152
-
153
259
  return Promise.resolve(
154
260
  DateFunctionRepository.filterableNames.filter(
155
261
  (e) => e.toLowerCase().indexOf(name.toLowerCase()) !== -1,
156
262
  ),
157
263
  );
158
264
  }
159
- }
265
+ }
@@ -0,0 +1,75 @@
1
+ import { Schema } from '../../../json/schema/Schema';
2
+ import { SchemaType } from '../../../json/schema/type/SchemaType';
3
+ import { TypeUtil } from '../../../json/schema/type/TypeUtil';
4
+ import { EventResult } from '../../../model/EventResult';
5
+ import { FunctionOutput } from '../../../model/FunctionOutput';
6
+ import { FunctionSignature } from '../../../model/FunctionSignature';
7
+ import { Parameter } from '../../../model/Parameter';
8
+ import { Namespaces } from '../../../namespaces/Namespaces';
9
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
10
+ import { MapUtil } from '../../../util/MapUtil';
11
+ import { AbstractFunction } from '../../AbstractFunction';
12
+ import { AbstractDateFunction } from './AbstractDateFunction';
13
+
14
+ export class EpochToTimestamp extends AbstractFunction {
15
+ private readonly signature: FunctionSignature;
16
+ private readonly isSeconds: boolean;
17
+ private readonly paramName: string;
18
+
19
+ constructor(name: string, isSeconds: boolean) {
20
+ super();
21
+ this.paramName = `epoch${isSeconds ? 'Seconds' : 'Milliseconds'}`;
22
+ this.isSeconds = isSeconds;
23
+ this.signature = new FunctionSignature(name)
24
+ .setNamespace(Namespaces.DATE)
25
+ .setParameters(
26
+ new Map([
27
+ [
28
+ this.paramName,
29
+ Parameter.of(
30
+ this.paramName,
31
+ new Schema()
32
+ .setName(this.paramName)
33
+ .setType(
34
+ TypeUtil.of(
35
+ SchemaType.LONG,
36
+ SchemaType.INTEGER,
37
+ SchemaType.STRING,
38
+ ),
39
+ ),
40
+ ),
41
+ ],
42
+ ]),
43
+ )
44
+ .setEvents(
45
+ new Map([
46
+ [
47
+ AbstractDateFunction.EVENT_TIMESTAMP_NAME,
48
+ AbstractDateFunction.EVENT_TIMESTAMP,
49
+ ],
50
+ ]),
51
+ );
52
+ }
53
+
54
+ public getSignature(): FunctionSignature {
55
+ return this.signature;
56
+ }
57
+
58
+ protected internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
59
+ const epoch = parseInt(context.getArguments()?.get(this.paramName));
60
+ const timestamp = this.isSeconds ? epoch * 1000 : epoch;
61
+ if (isNaN(timestamp)) {
62
+ throw new Error(`Please provide a valid value for ${this.paramName}.`);
63
+ }
64
+ return Promise.resolve(
65
+ new FunctionOutput([
66
+ EventResult.outputOf(
67
+ MapUtil.of(
68
+ AbstractDateFunction.EVENT_TIMESTAMP_NAME,
69
+ new Date(timestamp).toISOString(),
70
+ ),
71
+ ),
72
+ ]),
73
+ );
74
+ }
75
+ }
@@ -0,0 +1,44 @@
1
+ import { DateTime } from 'luxon';
2
+ import { Schema } from '../../../json/schema/Schema';
3
+ import { EventResult } from '../../../model/EventResult';
4
+ import { FunctionOutput } from '../../../model/FunctionOutput';
5
+ import { Parameter } from '../../../model/Parameter';
6
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
7
+ import { MapUtil } from '../../../util/MapUtil';
8
+ import { AbstractDateFunction } from './AbstractDateFunction';
9
+
10
+ export class FromDateString extends AbstractDateFunction {
11
+ public static readonly PARAMETER_FORMAT_NAME = 'format';
12
+
13
+ public static readonly PARAMETER_TIMESTAMP_STRING_NAME = 'timestampString';
14
+
15
+ constructor() {
16
+ super(
17
+ 'FromDateString',
18
+ AbstractDateFunction.EVENT_TIMESTAMP,
19
+ Parameter.of(
20
+ FromDateString.PARAMETER_TIMESTAMP_STRING_NAME,
21
+ Schema.ofString(FromDateString.PARAMETER_TIMESTAMP_STRING_NAME),
22
+ ),
23
+ Parameter.of(
24
+ FromDateString.PARAMETER_FORMAT_NAME,
25
+ Schema.ofString(FromDateString.PARAMETER_FORMAT_NAME),
26
+ ),
27
+ );
28
+ }
29
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
30
+ const timestampString = context
31
+ .getArguments()
32
+ ?.get(FromDateString.PARAMETER_TIMESTAMP_STRING_NAME);
33
+
34
+ const format = context.getArguments()?.get(FromDateString.PARAMETER_FORMAT_NAME);
35
+
36
+ const dateTime = DateTime.fromFormat(timestampString, format);
37
+
38
+ return new FunctionOutput([
39
+ EventResult.outputOf(
40
+ MapUtil.of(AbstractDateFunction.EVENT_RESULT_NAME, dateTime.toISO()),
41
+ ),
42
+ ]);
43
+ }
44
+ }