HourExpression.js 929 B

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. /**
  3. * An $hour pipeline expression.
  4. * @see evaluate
  5. * @class HourExpression
  6. * @namespace mungedb-aggregate.pipeline.expressions
  7. * @module mungedb-aggregate
  8. * @constructor
  9. **/
  10. var HourExpression = module.exports = function HourExpression(){
  11. if (arguments.length !== 0) throw new Error("zero args expected");
  12. base.call(this);
  13. }, klass = HourExpression, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  14. // PROTOTYPE MEMBERS
  15. proto.getOpName = function getOpName(){
  16. return "$hour";
  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 hour between 0 and 23.
  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.getUTCHours();
  30. };