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

FatorVencimento quebrando para vencimento em 21/02/2025 (dia 9999) quando a data não é truncada #1016

Open
mvdf95 opened this issue Feb 17, 2025 · 0 comments

Comments

@mvdf95
Copy link

mvdf95 commented Feb 17, 2025

Constatamos que o BoletoNet estava gerando incorretamente os boletos com vencimento em 21/02/2025 . Ao analisar, verificamos que estávamos passando um objeto DateTime com hora DateTime(21, 02, 2025, 15 , 0, 0) como data de vencimento.

Como 21/02/2025 15:00 > 21/02/2025 00:00, o método entra no "while" do FatorVencimento já no dia 21/02, quando esse comportamento não deveria aparecer até o dia 22.

Para solucionar, passamos a gerar o objeto Boleto com a data de vencimento truncada (ex: dataVencimento.Date)

   public static long FatorVencimento(Boleto boleto)
        {
            var dateBase = new DateTime(1997, 10, 7, 0, 0, 0);

            //Verifica se a data esta dentro do range utilizavel
            var dataAtual = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            long rangeUtilizavel = Utils.DateDiff(DateInterval.Day, dataAtual, boleto.DataVencimento);

            if (rangeUtilizavel > 5500 || rangeUtilizavel < -3000)
                throw new Exception("Data do vencimento fora do range de utilização proposto pela CENEGESC. Comunicado FEBRABAN de n° 082/2012 de 14/06/2012");


            while (boleto.DataVencimento > dateBase.AddDays(9999))
                dateBase = boleto.DataVencimento.AddDays(-(((Utils.DateDiff(DateInterval.Day, dateBase, boleto.DataVencimento) - 9999) - 1) + 1000));

            return Utils.DateDiff(DateInterval.Day, dateBase, boleto.DataVencimento);
        }
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

1 participant