DayOfMonthExpression.js 962 B

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. /**
  3. * Get the DayOfMonth from a date.
  4. * @class DayOfMonthExpression
  5. * @namespace mungedb-aggregate.pipeline.expressions
  6. * @module mungedb-aggregate
  7. * @constructor
  8. **/
  9. var DayOfMonthExpression = module.exports = function DayOfMonthExpression(){
  10. if (arguments.length !== 0) throw new Error("zero args expected");
  11. base.call(this);
  12. }, klass = DayOfMonthExpression, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  13. // PROTOTYPE MEMBERS
  14. proto.getOpName = function getOpName(){
  15. return "$dayOfMonth";
  16. };
  17. proto.addOperand = function addOperand(expr) {
  18. this.checkArgLimit(1);
  19. base.prototype.addOperand.call(this, expr);
  20. };
  21. /**
  22. * Takes a date and returns the day of the month as a number between 1 and 31.
  23. * @method evaluate
  24. **/
  25. proto.evaluate = function evaluate(doc){
  26. this.checkArgCount(1);
  27. var date = this.operands[0].evaluate(doc);
  28. return date.getUTCDate();
  29. };