@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fincity/kirun-js",
3
- "version": "2.8.3",
3
+ "version": "2.8.4",
4
4
  "description": "Javascript Runtime for Kinetic Instructions",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -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: DurationUnits | undefined = undefined;
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, units);
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 PARAMETER_FROM_NAME = 'from';
13
- public static readonly PARAMETER_FROM = new Parameter(
14
- FromNow.PARAMETER_FROM_NAME,
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.PARAMETER_FROM,
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 from1 = context.getArguments()?.get(FromNow.PARAMETER_FROM_NAME);
52
- const fromDate = from1 === '' ? DateTime.now() : DateTime.fromISO(from1);
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: fromDate, style: format?.toLowerCase(), round, locale };
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.EVENT_RESULT_NAME,
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
- const unit = context
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(AbstractDateFunction.EVENT_TIMESTAMP_NAME, newDateTime.toISO()),
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() && !schema.getEnums()?.length) {
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.ofInteger('years')],
40
- ['quarters', Schema.ofInteger('quarters')],
41
- ['months', Schema.ofInteger('months')],
42
- ['weeks', Schema.ofInteger('weeks')],
43
- ['days', Schema.ofInteger('days')],
44
- ['hours', Schema.ofInteger('hours')],
45
- ['minutes', Schema.ofInteger('minutes')],
46
- ['seconds', Schema.ofLong('seconds')],
47
- ['milliseconds', Schema.ofLong('milliseconds')],
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.ofInteger('year')],
59
- ['month', Schema.ofInteger('month')],
60
- ['day', Schema.ofInteger('day')],
61
- ['hour', Schema.ofInteger('hour')],
62
- ['minute', Schema.ofInteger('minute')],
63
- ['second', Schema.ofLong('second')],
64
- ['millisecond', Schema.ofLong('millisecond')],
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)!),