/
isYesterday.ts
53 lines (51 loc) · 1.8 KB
/
isYesterday.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
import { isYesterday, subtractFromDate, toISO8601 } from '@terascope/utils';
import { FieldType } from '@terascope/types';
import {
ProcessMode, FunctionDefinitionType, FunctionDefinitionCategory, FieldValidateConfig
} from '../interfaces';
const date = new Date();
const currentTime = date.toISOString();
const yesterday = subtractFromDate(currentTime, { days: 1 });
const yesterdayDate = new Date(yesterday).toISOString();
export const isYesterdayConfig: FieldValidateConfig = {
name: 'isYesterday',
type: FunctionDefinitionType.FIELD_VALIDATION,
process_mode: ProcessMode.INDIVIDUAL_VALUES,
category: FunctionDefinitionCategory.DATE,
examples: [
{
args: {},
config: { version: 1, fields: { testField: { type: FieldType.String } } },
field: 'testField',
input: currentTime,
output: null,
description: 'represents current time'
},
{
args: {},
config: { version: 1, fields: { testField: { type: FieldType.Date } } },
field: 'testField',
input: [new Date(yesterdayDate).getTime(), 0],
output: new Date(yesterdayDate).getTime(),
serialize_output: toISO8601,
test_only: true,
},
{
args: {},
config: { version: 1, fields: { testField: { type: FieldType.String } } },
field: 'testField',
input: yesterdayDate,
output: yesterdayDate,
description: 'represents day before current time'
},
],
description: 'Returns the input if it is on the day before (utc-time), otherwise returns null',
accepts: [
FieldType.String,
FieldType.Date,
FieldType.Number
],
create() {
return isYesterday;
}
};