MonthExpression.js 949 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. /**
  3. * A $month pipeline expression.
  4. * @see evaluate
  5. * @class MonthExpression
  6. * @namespace mungedb-aggregate.pipeline.expressions
  7. * @module mungedb-aggregate
  8. * @constructor
  9. **/
  10. var MonthExpression = module.exports = function MonthExpression() {
  11. this.nargs = 1;
  12. base.call(this);
  13. }, klass = MonthExpression,
  14. base = require("./NaryExpression"),
  15. proto = klass.prototype = Object.create(base.prototype, {
  16. constructor: {
  17. value: klass
  18. }
  19. });
  20. // DEPENDENCIES
  21. var Expression = require("./Expression");
  22. // PROTOTYPE MEMBERS
  23. proto.getOpName = function getOpName() {
  24. return "$month";
  25. };
  26. /**
  27. * Takes a date and returns the month as a number between 1 and 12.
  28. * @method evaluate
  29. **/
  30. proto.evaluateInternal = function evaluateInternal(vars) {
  31. var date = this.operands[0].evaluateInternal(vars);
  32. return date.getUTCMonth();
  33. };
  34. /** Register Expression */
  35. Expression.registerExpression("$month", base.parse(MonthExpression));