RulesEngine icon indicating copy to clipboard operation
RulesEngine copied to clipboard

get the time difference wrong

Open grefus opened this issue 1 year ago • 1 comments

When I try to calculate the TotalMinutes of the time difference between two DateTime values, it always results in an error.Here is my code below. Image Image Image

grefus avatar Dec 26 '24 01:12 grefus

@grefus I just tested this scenario using code approach and it works fine for me. check if your rules are formatted properly when loading from the JSON file. Also, please include the code does not screenshot. It's very hard to understand those screenshots.

public class GitHubTimeDifference
{

    public static async Task Run()
    {
        var workflows = new Workflow[]
        {
            new() {
                WorkflowName = "AlarmWorkflow",
                Rules =
                [
                    new Rule
                    {
                        RuleName = "CheckWithToString Convert",
                        RuleExpressionType = RuleExpressionType.LambdaExpression,
                        Expression = "(d2 - d1).TotalMinutes > 15",
                        ErrorMessage = "Time is not greater than 15 minutes",                        
                    }
                ]
            }
        };

      var d1 = DateTime.Now;
      var d2 = DateTime.Now.AddMinutes(20);

    var ruleParameters = new RuleParameter[] {
        new ("d1", d1),
        new ("d2", d2)
      };

        RE.RulesEngine rulesEngine = new(workflows);

        var resultList = await rulesEngine.ExecuteAllRulesAsync("AlarmWorkflow", ruleParameters);

        foreach (var result in resultList)
        {
            Console.WriteLine($"Rule: {result.Rule.RuleName}, Result: {result.IsSuccess}, Message: {result.ExceptionMessage}");           
        }
    }
}

Image

vamsidogiparthi avatar Feb 04 '25 21:02 vamsidogiparthi