DayOfMonthExpression.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. this.fixedArity(1);
  11. if (arguments.length !== 1) throw new Error("one args expected");
  12. base.call(this);
  13. }, klass = DayOfMonthExpression,
  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 "$dayOfMonth";
  25. };
  26. /**
  27. * Takes a date and returns the day of the month as a number between 1 and 31.
  28. * @method evaluate
  29. **/
  30. proto.evaluateInternal = function evaluateInternal(doc) {
  31. var date = this.operands[0].evaluateInternal(doc);
  32. return date.getUTCDate();
  33. };
  34. /** Register Expression */
  35. Expression.registerExpression("$dayOfMonth", DayOfMonthExpression.parse);