SecondExpression.js 905 B

123456789101112131415161718192021222324252627
  1. var SecondExpression = module.exports = (function(){
  2. // CONSTRUCTOR
  3. /** A $second pipeline expression. @see evaluate **/
  4. var klass = function SecondExpression(){
  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. // PROTOTYPE MEMBERS
  9. proto.getOpName = function getOpName(){
  10. return "$second";
  11. };
  12. proto.addOperand = function addOperand(expr) {
  13. this.checkArgLimit(1);
  14. base.addOperand(expr);
  15. };
  16. /** Takes a date and returns the second between 0 and 59, but can be 60 to account for leap seconds. **/
  17. proto.evaluate = function evaluate(doc){
  18. this.checkArgCount(1);
  19. var date = this.operands[0].evaluate(doc);
  20. return date.getSeconds(); //TODO: incorrect for last second of leap year, need to fix...
  21. };
  22. return klass;
  23. })();