-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
parsing.js
37 lines (30 loc) · 1.38 KB
/
parsing.js
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
const { TimexProperty } = require('@microsoft/recognizers-text-data-types-timex-expression');
// The TimexProperty class takes a TIMEX expression as a string argument in its constructor.
// This pulls all the component parts of the expression into properties on this object. You can
// then manipulate the TIMEX expression via those properties.
// The "Types" property infers a datetimeV2 type from the underlying set of properties.
// If you take a TIMEX with date components and add time components you add the
// inferred type datetime (its still a date).
// Logic can be written against the inferred type, perhaps to have the bot ask the user for disamiguation.
const describe = ({ timex, types }) => {
const messages = [timex];
if (types.has('date')) {
if (types.has('definite')) {
messages.push('We have a definite calendar date.');
} else {
messages.push('We have a date but there is some ambiguity.');
}
}
if (types.has('time')) {
messages.push('We have a time.');
}
console.log(messages.join(' '));
};
module.exports.examples = () => {
describe(new TimexProperty('2017-05-29'));
describe(new TimexProperty('XXXX-WXX-6'));
describe(new TimexProperty('XXXX-WXX-6T16'));
describe(new TimexProperty('T12'));
};