It appears that there are two errors in this situation.
- You are attempting to utilize Date functions on a Number data type.
- The function Date#setDate() requires the argument to be the day of a month, not the timestamp itself.
Date vs. Number
Issue
If you were to use new Date(response.data.data.dateReceived) to convert the milliseconds into a Date data type, you would have access to methods like setDate().
However, in your current code, you are trying to execute setDate() on what JavaScript perceives as just a regular number. To JavaScript, it may as well be -1, as it doesn't recognize any significance beyond its numeric value.
Resolution
Given that your input data is in milliseconds (as mentioned in the comments), a simple solution would be to add milliseconds to your original timestamp like this:
const SIXTY_DAYS = 5184e6; //1000ms/sec * 3600secs/hour * 24hours/day * 60days
$rootScope.until = response.data.data.dateReceived + SIXTY_DAYS;
Ensure that the value is a number and not a string to avoid concatenation instead of addition.
setDate arguments
Issue
If you do have a variable with a Date data type (as mentioned earlier), you would have access to methods like Date.setDate(). However, the arguments for this method differ from what your code assumes.
Resolution
setDate() requires a number representing days since the start of the month as its argument. To add a specific number of days, you can use the following code:
$rootScope.until = new Date(response.data.data.dateReceived);
$rootScope.until.setDate($rootScope.until.getDate() + 60);
This code will calculate the day of the month for the date, then add 60 days to that value, automatically adjusting for changes in the month.