SecondExpression.js 1.0 KB

1234567891011121314151617181920212223242526272829
  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.prototype.addOperand.call(this, 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. // currently leap seconds are unsupported in v8
  22. // http://code.google.com/p/v8/issues/detail?id=1944
  23. };
  24. return klass;
  25. })();