DayOfMonthExpression.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  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 !== 0) throw new Error("zero args expected");
  12. base.call(this);
  13. }, klass = DayOfMonthExpression, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  14. // DEPENDENCIES
  15. var Expression = require("./Expression");
  16. // PROTOTYPE MEMBERS
  17. proto.getOpName = function getOpName(){
  18. return "$dayOfMonth";
  19. };
  20. /**
  21. * Takes a date and returns the day of the month as a number between 1 and 31.
  22. * @method evaluate
  23. **/
  24. proto.evaluateInternal = function evaluateInternal(doc){
  25. this.checkArgCount(1);
  26. var date = this.operands[0].evaluateInternal(doc);
  27. return date.getUTCDate();
  28. };
  29. /** Register Expression */
  30. Expression.registerExpression("$dayOfMonth",DayOfMonthExpression.parse);