Moment JS - Some date functions


       


exports.getDateByRange = function(req, options) {

  var start_date = req.param('start_date');
  var end_date = req.param('end_date');
  var date_type = req.param('date_type') || "yesterday_revenue";

  if (date_type == "yesterday_revenue") {

    options.start_date = moment().subtract(1, 'day').startOf('day')._d;
    options.end_date = moment().subtract(1, 'day').startOf('day').add({
      hour: 23,
      minute: 59
    })._d;

  } else if (date_type == "week_to_date_revenue") {

    options.start_date = moment().startOf('week')._d;
    options.end_date = moment()._d;

  } else if (date_type == "month_to_date_revenue") {

    options.start_date = moment().startOf('month')._d;
    options.end_date = moment()._d;


  } else if (date_type == "quarter_to_date_revenue") {

    options.start_date = moment().startOf('quarter')._d;
    options.end_date = moment()._d;

  }

  return options;

}

Comments

Popular posts from this blog

Design a notification system

NETFLIX HIGH-LEVEL SYSTEM DESIGN

URL Shortener System Design