HourExpression.js 815 B

1234567891011121314151617181920212223242526272829
  1. var HourExpression = module.exports = (function(){
  2. // CONSTRUCTOR
  3. /** An $hour pipeline expression. @see evaluate **/
  4. var klass = function HourExpression(){
  5. if(arguments.length !== 0) throw new Error("zero args expected");
  6. base.call(this);
  7. }, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  8. // PROTOTYPE MEMBERS
  9. proto.getOpName = function getOpName(){
  10. return "$hour";
  11. };
  12. proto.addOperand = function addOperand(expr) {
  13. this.checkArgLimit(1);
  14. base.prototype.addOperand.call(this, expr);
  15. };
  16. /**
  17. * Takes a date and returns the hour between 0 and 23.
  18. **/
  19. proto.evaluate = function evaluate(doc){
  20. this.checkArgCount(1);
  21. var date = this.operands[0].evaluate(doc);
  22. return date.getHours();
  23. };
  24. return klass;
  25. })();