YearExpression.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. var YearExpression = module.exports = (function(){
  2. // CONSTRUCTOR
  3. /**
  4. * A $year pipeline expression.
  5. *
  6. * @see evaluate
  7. * @class YearExpression
  8. * @namespace munge.pipeline.expressions
  9. * @module munge
  10. * @constructor
  11. **/
  12. var klass = function YearExpression(){
  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. // DEPENDENCIES
  17. var Value = require("../Value"),
  18. DayOfYearExpression = require("./DayOfYearExpression");
  19. // PROTOTYPE MEMBERS
  20. proto.getOpName = function getOpName(){
  21. return "$year";
  22. };
  23. proto.addOperand = function addOperand(expr) {
  24. this.checkArgLimit(1);
  25. base.prototype.addOperand.call(this, expr);
  26. };
  27. /** Takes a date and returns the full year. **/
  28. proto.evaluate = function evaluate(doc) {
  29. this.checkArgCount(1);
  30. var date = this.operands[0].evaluate(doc);
  31. return date.getFullYear();
  32. };
  33. return klass;
  34. })();