/
toMonthlyDate.ts
73 lines (71 loc) · 2.25 KB
/
toMonthlyDate.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import {
DateFormat, FieldType, ISO8601DateSegment
} from '@terascope/types';
import { toISO8601, trimISODateSegment } from '@terascope/utils';
import {
FieldTransformConfig,
ProcessMode,
FunctionDefinitionType,
FunctionDefinitionCategory
} from '../interfaces';
export const toMonthlyDateConfig: FieldTransformConfig = {
name: 'toMonthlyDate',
type: FunctionDefinitionType.FIELD_TRANSFORM,
process_mode: ProcessMode.INDIVIDUAL_VALUES,
category: FunctionDefinitionCategory.DATE,
description: 'Converts a value to a monthly ISO 8601 date segment',
examples: [
{
args: { },
config: {
version: 1,
fields: { testField: { type: FieldType.Date, format: DateFormat.iso_8601 } }
},
field: 'testField',
input: '2019-10-22T01:00:00.000Z',
output: new Date('2019-10-01T00:00:00.000Z').getTime(),
serialize_output: toISO8601
},
{
args: { },
config: {
version: 1,
fields: { testField: { type: FieldType.Date, format: DateFormat.iso_8601 } }
},
field: 'testField',
input: [new Date('2019-10-22T01:00:00.000Z').getTime(), 120],
output: new Date('2019-10-01T00:00:00.000Z').getTime(),
serialize_output: toISO8601
},
{
args: { },
config: {
version: 1,
fields: { testField: { type: FieldType.Date, format: DateFormat.iso_8601 } }
},
field: 'testField',
input: '2018-01-22T18:00:00.000Z',
output: new Date('2018-01-01T00:00:00.000Z').getTime(),
serialize_output: toISO8601
},
],
create() {
return trimISODateSegment(ISO8601DateSegment.monthly);
},
accepts: [
FieldType.String,
FieldType.Number,
FieldType.Date
],
argument_schema: {},
output_type(inputConfig) {
const { field_config } = inputConfig;
return {
field_config: {
description: field_config.description,
array: field_config.array,
type: FieldType.Date
},
};
}
};