DSL for date handling

I have an existing asp.net application (C #). I need to provide a way for users to create flexible computing rules to calculate effective date based on hiring and registration.

Some examples of rules that can be used:

  • Later from the number of hired or registered users
  • HireDate + 90 days
  • First month after registration date
  • If the registration date is before the 15th day of the month, then the effective date is the 1st day of the next month. If it is on or after 15, it is the 1st month after that.

I started with a few offset fields (date offset, month offset, etc.), but when I come across new requirements, I start to realize that the current approach isn't flexible enough.

I would like to do this so that the end user can define a function that returns a date with two parameters (hiredate, enrollmentdate) and stores that function in the database. When I need to compute effectivedate, I would pull this function out of the database by executing it, passing parameters to get my efficiency.

What I need (I think) is a domain language (DSL) that would allow this function to be created. This syntax should make it easy to manipulate dates.

I am looking for DSL recommendations that fit my requirements. If my DSL strategy is disabled, we recommend a different path. Thank.

+3


source to share


2 answers


I am currently implementing my solution using the flee expression parser . This allows me to use most of the methods and properties provided to me by the .NET DateTime construct. I was pointed in this direction by re-posting my question like below:



fooobar.com/questions/1994175 / ...

0


source


I haven't seen a DSL like this (and I spent a lot of time on related topics).

Allowing users to specify date and time expressions is a very difficult issue. My own Natural Language Engine might be a good starting point or a good place to get some ideas.

In this engine, I have a concept TemporalExpression

. The NLP engine can parse strings as hard as "last year on Friday through 5 pm in May" and create an exact expression tree for them. If you pull various packages Abodit

from Nuget, you can explore classes and methods around this idea. There are also classes for units of measure, including time slots, which can help ( TimeSpan

for example, cannot handle "1 month and 2 days").



You can extend the engine to analyze your tokens (both simple ones, for example, and "hiring dates" or complex, for example, recognizing a given holiday by name to create a new one TemporalExpression

).

You can also look at DAML and OWL-Time for ideas around representing temporal expressions on the Semantic Web.

Disclaimer: I wrote this, this is a link to my site, it still works, there is a new version coming soon with "production rules" and will significantly improve performance, happy to discuss offline, blah blah ...

+1


source







All Articles