2

The below function gives me the next business date:

function nextBusinessDate() {

      var today = moment();
      var tomorrow = today.add(1, 'days');

      // if saturday
      if (tomorrow.day() === 6) {
        tomorrow = tomorrow.add(2, 'days');
      } else if (tomorrow.day() === 0) {
        tomorrow = tomorrow.add(1, 'days');
      }

      return new Date(tomorrow._d);
    }

The date that it returns looks something like this:

myDate = nextBusinessDate();

// This is what myDate looks like in developer console
myDate: Fri Jun 19 2015 07:24:40 GMT-0400 (EDT)
__proto__: Invalid Date

The issue I am facing is that this wont get stored in firebase (which uses mongo I believe)

What am I missing here ?

runtimeZero
  • 26,466
  • 27
  • 73
  • 126

2 Answers2

1

As in this answer https://stackoverflow.com/a/26744045/1167456 you should not be using the _d method as it is a private method in the API. There is already a built-in converter to javascript Date for moment objects: .toDate()

Your return line should look like this:

return tomorrow.toDate();
Community
  • 1
  • 1
il-Kelma
  • 51
  • 1
  • 4
0

You shouldn't be using the private d. Try using .toDate().

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445