MonthExpression.js 831 B

123456789101112131415161718192021222324252627
  1. var MonthExpression = module.exports = (function(){
  2. // CONSTRUCTOR
  3. /** A $month pipeline expression. @see evaluate **/
  4. var klass = function MonthExpression(){
  5. if(arguments.length !== 0) throw new Error("zero args expected");
  6. base.call(this);
  7. }, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  8. // PROTOTYPE MEMBERS
  9. proto.getOpName = function getOpName(){
  10. return "$month";
  11. };
  12. proto.addOperand = function addOperand(expr) {
  13. this.checkArgLimit(1);
  14. base.prototype.addOperand.call(this, expr);
  15. };
  16. /** Takes a date and returns the month as a number between 1 and 12. **/
  17. proto.evaluate = function evaluate(doc){
  18. this.checkArgCount(1);
  19. var date = this.operands[0].evaluate(doc);
  20. return date.getMonth() + 1;
  21. };
  22. return klass;
  23. })();