Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get the time difference wrong #637

Open
grefus opened this issue Dec 26, 2024 · 1 comment
Open

get the time difference wrong #637

grefus opened this issue Dec 26, 2024 · 1 comment

Comments

@grefus
Copy link

grefus commented Dec 26, 2024

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

@vamsidogiparthi
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants