Using:
var ld = DOpus.Create.Date("31-12-2023");
DOpus.Output(ld.Format());
ld.Sub(1, 'M');
DOpus.Output(ld.Format()); //keeps in dec, november expected
ld.Sub(1, 'M');
DOpus.Output(ld.Format()); //goes to november
ld.Sub(1, 'M');
ld.day = 31; //set date to Oct 31, to reproduce the issue
DOpus.Output(ld.Format()); //goes to october
ld.Sub(1, 'M');
DOpus.Output(ld.Format()); //keeps in oct, september expected
ld.Sub(1, 'M');
DOpus.Output(ld.Format()); //goes to september
ld.Sub(1, 'M');
ld.day = 31; //set date to Aug 31
DOpus.Output(ld.Format()); //goes to august
ld.Sub(1, 'M');
DOpus.Output(ld.Format()); //goes back as intended, since both months has 31 days
We can see that when the current month has 31 days, and the previous month has 30 or less, subtracting 1 month only subtracts the total number of days of the previous month, which can cause errors in any script that uses this method to go backwards by months. (Assuming Sub()
is intended to do that, substract by months despite the total days).
Using Add()
also gives unexpected results for me:
var ld = DOpus.Create.Date("31-07-2023");
DOpus.Output(ld.Format()); //Prints 31-07-2023
ld.Add(1, 'M');
DOpus.Output(ld.Format()); //Prints 31-08-2023
ld.Add(1, 'M');
DOpus.Output(ld.Format()); //Prints 01-10-2023, skipping september
ld.day = 31; //Set to 31-10-2023
ld.Add(1, 'M');
DOpus.Output(ld.Format()); //Prints 01-12-2023, skipping november
Is this something intended?