@fincity/kirun-js 2.8.3 → 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/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/package.json
CHANGED
|
@@ -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
|
}
|
|
@@ -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)!),
|