/
toTimeZone.ts
119 lines (116 loc) · 3.7 KB
/
toTimeZone.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import {
DateFormat, FieldType
} from '@terascope/types';
import { toTimeZone } from '@terascope/utils';
import {
FieldTransformConfig,
ProcessMode,
FunctionDefinitionType,
FunctionDefinitionCategory
} from '../interfaces';
export interface toTimeZoneArgs {
timezone: string
}
export const toTimeZoneConfig: FieldTransformConfig<toTimeZoneArgs> = {
name: 'toTimeZone',
type: FunctionDefinitionType.FIELD_TRANSFORM,
process_mode: ProcessMode.INDIVIDUAL_VALUES,
category: FunctionDefinitionCategory.DATE,
description: 'Converts a value to local time',
examples: [
{
args: { timezone: 'Africa/Ndjamena' },
config: {
version: 1,
fields: { testField: { type: FieldType.Date, format: DateFormat.iso_8601 } }
},
field: 'testField',
input: '2001-03-19T10:36:44.450Z',
output: '2001-03-19T11:36:44.450+01:00',
},
{
args: { timezone: 'Africa/Ndjamena' },
config: {
version: 1,
fields: { testField: { type: FieldType.Date, format: DateFormat.iso_8601 } }
},
field: 'testField',
input: new Date('2001-03-19T10:36:44.450Z'),
output: '2001-03-19T11:36:44.450+01:00',
},
{
args: { timezone: 'America/Phoenix' },
config: {
version: 1,
fields: { testField: { type: FieldType.Date, format: DateFormat.iso_8601 } }
},
field: 'testField',
input: '2023-08-22T15:41:50.172Z',
output: '2023-08-22T08:41:50.172-07:00',
},
{
args: { timezone: 'America/New_York' },
config: {
version: 1,
fields: { testField: { type: FieldType.Date, format: DateFormat.iso_8601 } }
},
field: 'testField',
input: '2023-08-22T15:41:50.172Z',
output: '2023-08-22T11:41:50.172-04:00',
},
{
args: { timezone: 'America/New_York' },
config: {
version: 1,
fields: { testField: { type: FieldType.Date, format: DateFormat.iso_8601 } }
},
field: 'testField',
input: '2023-11-22T15:41:50.172Z',
output: '2023-11-22T10:41:50.172-05:00',
},
{
args: { timezone: 'America/Phoenix' },
config: {
version: 1,
fields: { testField: { type: FieldType.Date, format: DateFormat.iso_8601 } }
},
field: 'testField',
input: '2023-11-22T15:41:50.172Z',
output: '2023-11-22T08:41:50.172-07:00',
},
{
args: { timezone: 'Asia/Calcutta' },
config: {
version: 1,
fields: { testField: { type: FieldType.Date, format: DateFormat.iso_8601 } }
},
field: 'testField',
input: '2023-11-22T15:41:50.172Z',
output: '2023-11-22T21:11:50.172+05:30',
},
],
create({ args: { timezone } }) {
return (val) => toTimeZone(val, timezone);
},
accepts: [
FieldType.String,
FieldType.Number,
FieldType.Date,
],
argument_schema: {
timezone: {
type: FieldType.String,
description: 'The timezone that the date will be shown in'
}
},
required_arguments: ['timezone'],
output_type(inputConfig) {
const { field_config } = inputConfig;
return {
field_config: {
...field_config,
type: FieldType.Date
},
};
}
};