-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTimeWindowFilter.ts
More file actions
33 lines (27 loc) · 1.23 KB
/
TimeWindowFilter.ts
File metadata and controls
33 lines (27 loc) · 1.23 KB
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { IFeatureFilter } from "./FeatureFilter.js";
// [Start, End)
type TimeWindowParameters = {
Start?: string;
End?: string;
}
type TimeWindowFilterEvaluationContext = {
featureName: string;
parameters: TimeWindowParameters;
}
export class TimeWindowFilter implements IFeatureFilter {
name: string = "Microsoft.TimeWindow";
evaluate(context: TimeWindowFilterEvaluationContext): boolean {
const {featureName, parameters} = context;
const startTime = parameters.Start !== undefined ? new Date(parameters.Start) : undefined;
const endTime = parameters.End !== undefined ? new Date(parameters.End) : undefined;
if (startTime === undefined && endTime === undefined) {
// If neither start nor end time is specified, then the filter is not applicable.
console.warn(`The ${this.name} feature filter is not valid for feature ${featureName}. It must specify either 'Start', 'End', or both.`);
return false;
}
const now = new Date();
return (startTime === undefined || startTime <= now) && (endTime === undefined || now < endTime);
}
}