HourExpression.js 934 B

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