Closed sadie-niblett closed 2 weeks ago
Ok taking another look, they both work but in different ways. It seems like the .AddMonths() method simply changes the number representing the month while the method that uses .AddDays() adds the days before converting the new time back into month/day/year. But not every month has 30 days, so these method won't quite line up. For example, if we went to add 5 months to a date of 01/01/2023, the .AddMonths(5) method would return 06/01/2023, while the method that uses .AddDays(530) would return 5/31/2023. We just need to figure out which way we want this method to work so we can test it. Right now the tests I have written pass if we're using the .AddMonth(n) method, but will not pass with the .AddDays(n30) method.
I will leave this open for now.
I need this method for computing Water Years, which begin the first of October. Shift by month doesn't do exactly what I want. Shift by days (number of months + 30) works better for preserving the true date when shifting back.
I added a shift dates by day sub routine and restored the shift dates by month option. I added tests for each.
In TimeSeries.cs, in the ShiftDatesByMonth method there are 2 lines of code that acomplish the same thing: ordinate.Index = this[i].Index.AddMonths(numberOfMonths); ordinate.Index = this[i].Index.AddDays(numberOfMonths * 30);
The first line is commented out. I uncommented and commented out the second line just to see if it would pass the test I had written for the method and it did. I'm not sure which way you'd prefer, so they're both still in the file with the first commented out.