Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private extractDates(message: string, fromLocale: string): TextAndDateTime[] {
// let fndDates: string[];
let culture: string = DateTimeRecognizers.Culture.English;
if (fromLocale.startsWith('fr')) {
culture = DateTimeRecognizers.Culture.French;
} else if (fromLocale.startsWith('pt')) {
culture = DateTimeRecognizers.Culture.Portuguese;
} else if (fromLocale.startsWith('zh')) {
culture = DateTimeRecognizers.Culture.Chinese;
} else if (fromLocale.startsWith('es')) {
culture = DateTimeRecognizers.Culture.Spanish;
} else if (!fromLocale.startsWith('en')) {
throw new Error('Unsupported from locale');
}
const model: DateTimeRecognizers.IDateTimeModel = new DateTimeRecognizers.DateTimeRecognizer(culture).getDateTimeModel();
const results: ModelResult[] = model.parse(message);
const foundDates: TextAndDateTime[] = [];
results.forEach((result: ModelResult) => {
let curDateTimeText: TextAndDateTime;
let momentTime: Date;
let momentTimeEnd: Date;
let foundType: string;
const resolutionValues: any = result.resolution.values[0];
const type: string = result.typeName.replace('datetimeV2.', '');
if (type.includes('range')) {
if (type.includes('date') && type.includes('time')) {
momentTime = moment(resolutionValues.start).toDate();
momentTimeEnd = moment(resolutionValues.end).toDate();
foundType = 'datetime';
} else if (type.includes('date')) {
if (fromLocale.startsWith("fr")) {
culture = DateTimeRecognizers.Culture.French;
}
else if (fromLocale.startsWith("pt")) {
culture = DateTimeRecognizers.Culture.Portuguese;
}
else if (fromLocale.startsWith("zh")) {
culture = DateTimeRecognizers.Culture.Chinese;
}
else if (fromLocale.startsWith("es")) {
culture = DateTimeRecognizers.Culture.Spanish;
}
else if (!fromLocale.startsWith("en")) {
throw new Error("Unsupported from locale");
}
let model = new DateTimeRecognizers.DateTimeRecognizer(culture).getDateTimeModel();
let results = model.parse(message);
let foundDates = [];
results.forEach(result => {
let curDateTimeText;
let momentTime;
let momentTimeEnd;
let foundType;
let resolutionValues = result.resolution["values"][0];
let type = result.typeName.replace('datetimeV2.', '');
if (type.includes('range')) {
if (type.includes('date') && type.includes('time')) {
momentTime = moment(resolutionValues["start"]).toDate();
momentTimeEnd = moment(resolutionValues["end"]).toDate();
foundType = 'datetime';
}
else if (type.includes('date')) {