YearExpression.js 910 B

12345678910111213141516171819202122232425262728293031
  1. var YearExpression = module.exports = (function(){
  2. // CONSTRUCTOR
  3. /** A $year pipeline expression. @see evaluate **/
  4. var klass = function YearExpression(){
  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. // DEPENDENCIES
  9. var Value = require("../Value"),
  10. DayOfYearExpression = require("./DayOfYearExpression");
  11. // PROTOTYPE MEMBERS
  12. proto.getOpName = function getOpName(){
  13. return "$year";
  14. };
  15. proto.addOperand = function addOperand(expr) {
  16. this.checkArgLimit(1);
  17. base.prototype.addOperand.call(this, expr);
  18. };
  19. /** Takes a date and returns the full year. **/
  20. proto.evaluate = function evaluate(doc) {
  21. this.checkArgCount(1);
  22. var date = this.operands[0].evaluate(doc);
  23. return date.getFullYear();
  24. };
  25. return klass;
  26. })();