Q:

Add/subtract minutes from current date

My goal is to have current date/time offset by given amount of minutes (negative or positive).
I went through many posts on Internet, but they're all using getMinutes()-minutes type of solutions, which will not take care of negative minutes or before/after midnight date changes.
I'm getting Uncaught TypeError: undefined is not a function if I specify negativeOffset or positiveOffset. Please advice.
function currentDateTime(negativeOffset, positiveOffset) {
    var newDate = new Date();
    newDate = (negativeOffset) ? newDate.getTime() - negativeOffset * 60000 : newDate;
    newDate = (positiveOffset) ? newDate.getTime() + positiveOffset * 60000 : newDate;
    var currentDate = ('0' + (newDate.getMonth()+1)).slice(-2) + '/' + ('0' + newDate.getDate()).slice(-2) + '/' + newDate.getFullYear();
    var currentHour = newDate.getHours() % 12;
    currentHour = currentHour ? currentHour : 12;
    currentHour = ('0' + (currentHour)).slice(-2);
    var currentMinute = ('0' + newDate.getMinutes()).slice(-2)
    var currentAmPm = (newDate.getHours() >= 12) ? 'pm' : 'am';
    var currentTime = currentHour + ':' + currentMinute + ' ' + currentAmPm;
    return[currentDate, currentTime];
}

A:

newDate = (negativeOffset) ? newDate.getTime() - negativeOffset * 60000 : newDate;
newDate = (positiveOffset) ? newDate.getTime() + positiveOffset * 60000 : newDate;

after this your newDate variable becomes integer, you should use
newDate = (negativeOffset) ? new Date(newDate.getTime() - negativeOffset * 60000) : newDate;
newDate = (positiveOffset) ? new Date(newDate.getTime() + positiveOffset * 60000) : newDate;

to keep it as Date object

