MinuteExpression.js 945 B

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