MonthExpression.js 952 B

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