DayOfWeekExpression.js 815 B

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