Using LUIS engine, I receive XXXX-10-28
as a date in the Entity Value.
I've tried using Chronic
to parse but Chronic does not work with timex
library/formats.
I'm expecting following strings as inputs
XXXX-10-28
should equate to 2018-10-28
(future)2018-10-02TMO
should equate to 2018-10-02
i.e. tomorrow
Please note that XXXX-XX
represents YYYY-MM
but it doesn't have numeric
values
Is there any library, or way to parse such strings to a valid datetime
format in ASP.NET Core
?
You can use the Microsoft.Recognizers.Text.DataTypes.TimexExpression package from NuGet. It's part of the Microsoft Recognizers Text project here on github
I found two ways you can use this library:
var parsed = new Microsoft.Recognizers.Text.DataTypes.TimexExpression.TimexProperty("XXXX-10-28");
Console.WriteLine(parsed.Year); // = null
Console.WriteLine(parsed.Month); // = 28
Console.WriteLine(parsed.DayOfMonth); // = 10
var resolution = Microsoft.Recognizers.Text.DataTypes.TimexExpression.TimexResolver.Resolve(new [] { "XXXX-10-28" }, System.DateTime.Today)
The resolution.Values
will contain an array with two resolution entries, one for the previous occurrence of that date and one for the next occurrence of that date (based on the DateTime you pass into the Resolve method.
Note that from personal experience and from what I saw on github, that at the time of writing, this package can be quite buggy with the more advanced expressions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With