DayOfWeekExpression.js 972 B

12345678910111213141516171819202122232425262728293031323334
  1. var DayOfWeekExpression = module.exports = (function(){
  2. // CONSTRUCTOR
  3. /**
  4. * Get the DayOfWeek from a date.
  5. *
  6. * @class DayOfWeekExpression
  7. * @namespace munge.pipeline.expressions
  8. * @module munge
  9. * @constructor
  10. **/
  11. var klass = function DayOfWeekExpression(){
  12. if(arguments.length !== 0) throw new Error("zero args expected");
  13. base.call(this);
  14. }, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  15. // PROTOTYPE MEMBERS
  16. proto.getOpName = function getOpName(){
  17. return "$dayOfWeek";
  18. };
  19. proto.addOperand = function addOperand(expr) {
  20. this.checkArgLimit(1);
  21. base.prototype.addOperand.call(this, expr);
  22. };
  23. /** Takes a date and returns the day of the week as a number between 1 (Sunday) and 7 (Saturday.) **/
  24. proto.evaluate = function evaluate(doc){
  25. this.checkArgCount(1);
  26. var date = this.operands[0].evaluate(doc);
  27. return date.getDay() + 1;
  28. };
  29. return klass;
  30. })();