Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Need help with a bug

awsdert

New Coder
Trying to build a simplified version of something I already built (so I don't have to keep updating so many parameters) but struggling to get different dates for something that is supposed to have multiple instances in a period of 4 weeks, if you open up the example you'll see that the "Rent" rows end up with the same date yet I cannot find a reason for this to occur, the sub function you'll be looking at is the 1st anonymous function that the variable "check" is assigned in fol.Calc()
 

Attachments

  • Cash Flow.zip
    2.1 KB · Views: 1
Trying to build a simplified version of something I already built (so I don't have to keep updating so many parameters) but struggling to get different dates for something that is supposed to have multiple instances in a period of 4 weeks, if you open up the example you'll see that the "Rent" rows end up with the same date yet I cannot find a reason for this to occur, the sub function you'll be looking at is the 1st anonymous function that the variable "check" is assigned in fol.Calc()
Can you please show your code here on CF using the </> button.

Thanks
 
Can you please show your code here on CF using the </> button.

Thanks
Too much for putting inside a single post, I can put the sub function fine but for context on everything else you'll need to look in the attached zip
JavaScript:
        var check = function( grab, days )
        {
            for ( var i = 0; i < grab.length; ++i )
            {
                var day = grab[i];
                day.M = fol.is(day.M) ? day.M : now.M;
                day.Y = now.Y + (day.M < prv.M);
                var date;

                if ( days > 7 )
                    date = new Date( day.Y, day.M - 1, day.D );
                else
                {
                    date = new Date( prv.date );
                    while ( date.getDay() != day.D )
                        date.setDate( date.getDate() + 1 );
                }

                while ( date >= prv.date && date < nxt.date )
                {
                    var obj = new Object(day);
                    obj.Y = date.getFullYear();
                    obj.M = date.getMonth() + 1;
                    obj.D = date.getDate();
                    obj.date = new Date( obj.Y, obj.M - 1, obj.D );

                    if ( date > now.date )
                        still += obj.C;
                    else
                        obj.Class = "paid";

                    list.push( obj );
                    date.setDate(obj.D + days);
                }
            }
        }

        check( out.getYear(), 365 );
        check( out.getDate(), 28 );
        check( out.getDay(), 7 );
 
Shouldn't this set something?
Code:
if ( temp > 5 )
    nxt.date.setDate(nxt.date.getDate() + (8 - temp));
Yeah that one works as intended, basically if the expected date falls on the weekend it's assumed that it will be pushed back until monday

*Edit:* It's just the obj.date = new Date(...) that's not working as expected
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom