@fincity/kirun-js 2.8.3 → 2.8.5
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/generator/validation-js.csv +14 -14
- package/package.json +1 -1
- package/src/engine/function/system/date/AbstractDateFunction.ts +1 -1
- package/src/engine/function/system/date/DateFunctionRepository.ts +5 -4
- package/src/engine/function/system/date/EpochToTimestamp.ts +1 -1
- package/src/engine/function/system/date/FromNow.ts +7 -7
- package/src/engine/function/system/date/LastFirstOf.ts +1 -1
- 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/TimestampToEpoch.ts +4 -1
- 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
|
@@ -368,7 +368,7 @@ System.Date.EpochMillisecondsToTimestamp
|
|
|
368
368
|
Parameter,Type,Schema
|
|
369
369
|
epochMilliseconds,EXPRESSION,integer;long;string
|
|
370
370
|
Events
|
|
371
|
-
|
|
371
|
+
output,output
|
|
372
372
|
Event Parameter,,Schema
|
|
373
373
|
isotimestamp,,
|
|
374
374
|
|
|
@@ -376,7 +376,7 @@ System.Date.EpochSecondsToTimestamp
|
|
|
376
376
|
Parameter,Type,Schema
|
|
377
377
|
epochSeconds,EXPRESSION,integer;long;string
|
|
378
378
|
Events
|
|
379
|
-
|
|
379
|
+
output,output
|
|
380
380
|
Event Parameter,,Schema
|
|
381
381
|
isotimestamp,,
|
|
382
382
|
|
|
@@ -384,7 +384,7 @@ System.Date.FirstOf
|
|
|
384
384
|
Parameter,Type,Schema
|
|
385
385
|
isoTimeStamp,EXPRESSION,
|
|
386
386
|
Events
|
|
387
|
-
|
|
387
|
+
output,output
|
|
388
388
|
Event Parameter,,Schema
|
|
389
389
|
isotimestamp,,
|
|
390
390
|
|
|
@@ -399,8 +399,8 @@ isotimestamp,,
|
|
|
399
399
|
|
|
400
400
|
System.Date.FromNow
|
|
401
401
|
Parameter,Type,Schema
|
|
402
|
+
base,EXPRESSION,
|
|
402
403
|
format,EXPRESSION,string
|
|
403
|
-
from,EXPRESSION,
|
|
404
404
|
isoTimeStamp,EXPRESSION,
|
|
405
405
|
locale,EXPRESSION,string
|
|
406
406
|
round,EXPRESSION,boolean
|
|
@@ -620,7 +620,7 @@ System.Date.LastOf
|
|
|
620
620
|
Parameter,Type,Schema
|
|
621
621
|
isoTimeStamp,EXPRESSION,
|
|
622
622
|
Events
|
|
623
|
-
|
|
623
|
+
output,output
|
|
624
624
|
Event Parameter,,Schema
|
|
625
625
|
isotimestamp,,
|
|
626
626
|
|
|
@@ -631,7 +631,7 @@ number,EXPRESSION,integer
|
|
|
631
631
|
Events
|
|
632
632
|
output,output
|
|
633
633
|
Event Parameter,,Schema
|
|
634
|
-
|
|
634
|
+
isotimestamp,,
|
|
635
635
|
|
|
636
636
|
System.Date.SetHours
|
|
637
637
|
Parameter,Type,Schema
|
|
@@ -640,7 +640,7 @@ number,EXPRESSION,integer
|
|
|
640
640
|
Events
|
|
641
641
|
output,output
|
|
642
642
|
Event Parameter,,Schema
|
|
643
|
-
|
|
643
|
+
isotimestamp,,
|
|
644
644
|
|
|
645
645
|
System.Date.SetMilliseconds
|
|
646
646
|
Parameter,Type,Schema
|
|
@@ -649,7 +649,7 @@ number,EXPRESSION,integer
|
|
|
649
649
|
Events
|
|
650
650
|
output,output
|
|
651
651
|
Event Parameter,,Schema
|
|
652
|
-
|
|
652
|
+
isotimestamp,,
|
|
653
653
|
|
|
654
654
|
System.Date.SetMinutes
|
|
655
655
|
Parameter,Type,Schema
|
|
@@ -658,7 +658,7 @@ number,EXPRESSION,integer
|
|
|
658
658
|
Events
|
|
659
659
|
output,output
|
|
660
660
|
Event Parameter,,Schema
|
|
661
|
-
|
|
661
|
+
isotimestamp,,
|
|
662
662
|
|
|
663
663
|
System.Date.SetMonth
|
|
664
664
|
Parameter,Type,Schema
|
|
@@ -667,7 +667,7 @@ number,EXPRESSION,integer
|
|
|
667
667
|
Events
|
|
668
668
|
output,output
|
|
669
669
|
Event Parameter,,Schema
|
|
670
|
-
|
|
670
|
+
isotimestamp,,
|
|
671
671
|
|
|
672
672
|
System.Date.SetSeconds
|
|
673
673
|
Parameter,Type,Schema
|
|
@@ -676,7 +676,7 @@ number,EXPRESSION,integer
|
|
|
676
676
|
Events
|
|
677
677
|
output,output
|
|
678
678
|
Event Parameter,,Schema
|
|
679
|
-
|
|
679
|
+
isotimestamp,,
|
|
680
680
|
|
|
681
681
|
System.Date.SetTimeZone
|
|
682
682
|
Parameter,Type,Schema
|
|
@@ -694,7 +694,7 @@ number,EXPRESSION,integer
|
|
|
694
694
|
Events
|
|
695
695
|
output,output
|
|
696
696
|
Event Parameter,,Schema
|
|
697
|
-
|
|
697
|
+
isotimestamp,,
|
|
698
698
|
|
|
699
699
|
System.Date.StartOf
|
|
700
700
|
Parameter,Type,Schema
|
|
@@ -740,7 +740,7 @@ System.Date.TimestampToEpochMilliseconds
|
|
|
740
740
|
Parameter,Type,Schema
|
|
741
741
|
isoTimeStamp,EXPRESSION,
|
|
742
742
|
Events
|
|
743
|
-
|
|
743
|
+
output,output
|
|
744
744
|
Event Parameter,,Schema
|
|
745
745
|
result,,long
|
|
746
746
|
|
|
@@ -748,7 +748,7 @@ System.Date.TimestampToEpochSeconds
|
|
|
748
748
|
Parameter,Type,Schema
|
|
749
749
|
isoTimeStamp,EXPRESSION,
|
|
750
750
|
Events
|
|
751
|
-
|
|
751
|
+
output,output
|
|
752
752
|
Event Parameter,,Schema
|
|
753
753
|
result,,long
|
|
754
754
|
|
package/package.json
CHANGED
|
@@ -222,7 +222,7 @@ export abstract class AbstractDateFunction extends AbstractFunction {
|
|
|
222
222
|
}
|
|
223
223
|
})(
|
|
224
224
|
name,
|
|
225
|
-
AbstractDateFunction.
|
|
225
|
+
AbstractDateFunction.EVENT_TIMESTAMP,
|
|
226
226
|
AbstractDateFunction.PARAMETER_TIMESTAMP,
|
|
227
227
|
AbstractDateFunction.PARAMETER_NUMBER,
|
|
228
228
|
),
|
|
@@ -10,7 +10,7 @@ import { EpochToTimestamp } from './EpochToTimestamp';
|
|
|
10
10
|
import { TimestampToEpoch } from './TimestampToEpoch';
|
|
11
11
|
import { ToDateString } from './ToDateString';
|
|
12
12
|
import { Schema } from '../../../json/schema/Schema';
|
|
13
|
-
import { DateTimeUnit, DurationUnits } from 'luxon';
|
|
13
|
+
import { DateTimeUnit, Duration, DurationUnits } from 'luxon';
|
|
14
14
|
import { SetTimeZone } from './SetTimeZone';
|
|
15
15
|
import { IsBetween } from './IsBetween';
|
|
16
16
|
import { LastFirstOf } from './LastFirstOf';
|
|
@@ -107,14 +107,15 @@ export class DateFunctionRepository implements Repository<Function> {
|
|
|
107
107
|
(ts1: string, ts2: string, extraParams: any[]) => {
|
|
108
108
|
const dt1 = getDateTime(ts1);
|
|
109
109
|
const dt2 = getDateTime(ts2);
|
|
110
|
-
let units:
|
|
110
|
+
let units: Array<DateTimeUnit> | undefined = undefined;
|
|
111
111
|
if (extraParams?.[0]?.length) {
|
|
112
112
|
units = extraParams[0]
|
|
113
113
|
?.filter((e: any) => !!e)
|
|
114
114
|
.map((e: string) => e.toLowerCase() as DateTimeUnit);
|
|
115
115
|
}
|
|
116
|
-
const duration = dt1.diff(dt2
|
|
117
|
-
return duration.toObject();
|
|
116
|
+
const duration = dt1.diff(dt2);
|
|
117
|
+
if (!units?.length) return duration.toObject();
|
|
118
|
+
return duration.shiftTo(...units).toObject();
|
|
118
119
|
},
|
|
119
120
|
AbstractDateFunction.PARAMETER_VARIABLE_UNIT,
|
|
120
121
|
),
|
|
@@ -9,9 +9,9 @@ import { MapUtil } from '../../../util/MapUtil';
|
|
|
9
9
|
import { AbstractDateFunction } from './AbstractDateFunction';
|
|
10
10
|
|
|
11
11
|
export class FromNow extends AbstractDateFunction {
|
|
12
|
-
public static readonly
|
|
13
|
-
public static readonly
|
|
14
|
-
FromNow.
|
|
12
|
+
public static readonly PARAMETER_BASE_NAME = 'base';
|
|
13
|
+
public static readonly PARAMETER_BASE = new Parameter(
|
|
14
|
+
FromNow.PARAMETER_BASE_NAME,
|
|
15
15
|
Schema.ofRef(Namespaces.DATE + '.Timestamp').setDefaultValue(''),
|
|
16
16
|
);
|
|
17
17
|
public static readonly PARAMETER_LOCALE_NAME = 'locale';
|
|
@@ -40,7 +40,7 @@ export class FromNow extends AbstractDateFunction {
|
|
|
40
40
|
AbstractDateFunction.EVENT_STRING,
|
|
41
41
|
AbstractDateFunction.PARAMETER_TIMESTAMP,
|
|
42
42
|
FromNow.PARAMETER_FORMAT,
|
|
43
|
-
FromNow.
|
|
43
|
+
FromNow.PARAMETER_BASE,
|
|
44
44
|
AbstractDateFunction.PARAMETER_VARIABLE_UNIT,
|
|
45
45
|
FromNow.PARAMETER_ROUND,
|
|
46
46
|
FromNow.PARAMETER_LOCALE,
|
|
@@ -48,8 +48,8 @@ export class FromNow extends AbstractDateFunction {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
public internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
|
|
51
|
-
const
|
|
52
|
-
const
|
|
51
|
+
const base = context.getArguments()?.get(FromNow.PARAMETER_BASE_NAME);
|
|
52
|
+
const baseDate = base === '' ? DateTime.now() : DateTime.fromISO(base);
|
|
53
53
|
const given = context.getArguments()?.get(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME);
|
|
54
54
|
const givenDate = DateTime.fromISO(given);
|
|
55
55
|
|
|
@@ -58,7 +58,7 @@ export class FromNow extends AbstractDateFunction {
|
|
|
58
58
|
const round = context.getArguments()?.get(FromNow.PARAMETER_ROUND_NAME);
|
|
59
59
|
const locale = context.getArguments()?.get(FromNow.PARAMETER_LOCALE_NAME);
|
|
60
60
|
|
|
61
|
-
const options: any = { base:
|
|
61
|
+
const options: any = { base: baseDate, style: format?.toLowerCase(), round, locale };
|
|
62
62
|
if (units?.length > 0) {
|
|
63
63
|
options.unit = units.map((e: string) => e.toLowerCase());
|
|
64
64
|
}
|
|
@@ -34,7 +34,7 @@ export class SetTimeZone extends AbstractDateFunction {
|
|
|
34
34
|
return new FunctionOutput([
|
|
35
35
|
EventResult.outputOf(
|
|
36
36
|
MapUtil.of(
|
|
37
|
-
AbstractDateFunction.
|
|
37
|
+
AbstractDateFunction.EVENT_TIMESTAMP_NAME,
|
|
38
38
|
dateTime.setZone(timeZone).toISO()!,
|
|
39
39
|
),
|
|
40
40
|
),
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { DurationLikeObject } from 'luxon';
|
|
2
|
-
import { Schema } from '../../../json/schema/Schema';
|
|
3
1
|
import { EventResult } from '../../../model/EventResult';
|
|
4
2
|
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
5
|
-
import { Parameter } from '../../../model/Parameter';
|
|
6
3
|
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
7
4
|
import { MapUtil } from '../../../util/MapUtil';
|
|
8
5
|
import { AbstractDateFunction } from './AbstractDateFunction';
|
|
@@ -28,16 +25,19 @@ export class StartEndOf extends AbstractDateFunction {
|
|
|
28
25
|
|
|
29
26
|
const dateTime = getDateTime(timestamp);
|
|
30
27
|
|
|
31
|
-
|
|
28
|
+
let unit = context
|
|
32
29
|
.getArguments()
|
|
33
30
|
?.get(AbstractDateFunction.PARAMETER_UNIT_NAME)
|
|
34
31
|
?.toLowerCase();
|
|
32
|
+
unit = unit.substring(0, unit.length - 1);
|
|
35
33
|
|
|
36
34
|
const newDateTime = this.isStart ? dateTime.startOf(unit) : dateTime.endOf(unit);
|
|
37
|
-
|
|
38
35
|
return new FunctionOutput([
|
|
39
36
|
EventResult.outputOf(
|
|
40
|
-
MapUtil.of(
|
|
37
|
+
MapUtil.of(
|
|
38
|
+
AbstractDateFunction.EVENT_TIMESTAMP_NAME,
|
|
39
|
+
newDateTime.toISO({ includeOffset: true }),
|
|
40
|
+
),
|
|
41
41
|
),
|
|
42
42
|
]);
|
|
43
43
|
}
|
|
@@ -28,7 +28,10 @@ export class TimestampToEpoch extends AbstractFunction {
|
|
|
28
28
|
)
|
|
29
29
|
.setEvents(
|
|
30
30
|
new Map([
|
|
31
|
-
[
|
|
31
|
+
[
|
|
32
|
+
AbstractDateFunction.EVENT_TIMESTAMP.getName(),
|
|
33
|
+
AbstractDateFunction.EVENT_LONG,
|
|
34
|
+
],
|
|
32
35
|
]),
|
|
33
36
|
);
|
|
34
37
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DateTime } from 'luxon';
|
|
2
2
|
|
|
3
3
|
export function getDateTime(isoTimestamp: string): DateTime {
|
|
4
|
-
let dt = DateTime.fromISO(isoTimestamp);
|
|
4
|
+
let dt = DateTime.fromISO(isoTimestamp, { setZone: true });
|
|
5
5
|
if (!dt?.isValid) {
|
|
6
6
|
throw new Error('Invalid ISO timestamp');
|
|
7
7
|
}
|
|
@@ -60,7 +60,7 @@ export class SchemaValidator {
|
|
|
60
60
|
return SchemaValidator.constantValidation(parents, schema, element);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
if (schema.getEnums()
|
|
63
|
+
if (schema.getEnums()?.length) {
|
|
64
64
|
return SchemaValidator.enumCheck(parents, schema, element);
|
|
65
65
|
}
|
|
66
66
|
|
|
@@ -36,15 +36,15 @@ const map: Map<string, Schema> = new Map([
|
|
|
36
36
|
.setNamespace(Namespaces.DATE)
|
|
37
37
|
.setProperties(
|
|
38
38
|
MapUtil.ofArrayEntries(
|
|
39
|
-
['years', Schema.
|
|
40
|
-
['quarters', Schema.
|
|
41
|
-
['months', Schema.
|
|
42
|
-
['weeks', Schema.
|
|
43
|
-
['days', Schema.
|
|
44
|
-
['hours', Schema.
|
|
45
|
-
['minutes', Schema.
|
|
46
|
-
['seconds', Schema.
|
|
47
|
-
['milliseconds', Schema.
|
|
39
|
+
['years', Schema.ofNumber('years')],
|
|
40
|
+
['quarters', Schema.ofNumber('quarters')],
|
|
41
|
+
['months', Schema.ofNumber('months')],
|
|
42
|
+
['weeks', Schema.ofNumber('weeks')],
|
|
43
|
+
['days', Schema.ofNumber('days')],
|
|
44
|
+
['hours', Schema.ofNumber('hours')],
|
|
45
|
+
['minutes', Schema.ofNumber('minutes')],
|
|
46
|
+
['seconds', Schema.ofNumber('seconds')],
|
|
47
|
+
['milliseconds', Schema.ofNumber('milliseconds')],
|
|
48
48
|
),
|
|
49
49
|
)
|
|
50
50
|
.setAdditionalItems(AdditionalType.from(false)!),
|
|
@@ -55,13 +55,13 @@ const map: Map<string, Schema> = new Map([
|
|
|
55
55
|
.setNamespace(Namespaces.DATE)
|
|
56
56
|
.setProperties(
|
|
57
57
|
MapUtil.ofArrayEntries(
|
|
58
|
-
['year', Schema.
|
|
59
|
-
['month', Schema.
|
|
60
|
-
['day', Schema.
|
|
61
|
-
['hour', Schema.
|
|
62
|
-
['minute', Schema.
|
|
63
|
-
['second', Schema.
|
|
64
|
-
['millisecond', Schema.
|
|
58
|
+
['year', Schema.ofNumber('year')],
|
|
59
|
+
['month', Schema.ofNumber('month')],
|
|
60
|
+
['day', Schema.ofNumber('day')],
|
|
61
|
+
['hour', Schema.ofNumber('hour')],
|
|
62
|
+
['minute', Schema.ofNumber('minute')],
|
|
63
|
+
['second', Schema.ofNumber('second')],
|
|
64
|
+
['millisecond', Schema.ofNumber('millisecond')],
|
|
65
65
|
),
|
|
66
66
|
)
|
|
67
67
|
.setAdditionalItems(AdditionalType.from(false)!),
|