SecondExpression.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. var SecondExpression = module.exports = (function(){
  2. // CONSTRUCTOR
  3. /**
  4. * An $second pipeline expression.
  5. *
  6. * @see evaluate
  7. * @class SecondExpression
  8. * @namespace munge.pipeline.expressions
  9. * @module munge
  10. * @constructor
  11. **/
  12. var klass = function SecondExpression(){
  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. // PROTOTYPE MEMBERS
  17. proto.getOpName = function getOpName(){
  18. return "$second";
  19. };
  20. proto.addOperand = function addOperand(expr) {
  21. this.checkArgLimit(1);
  22. base.prototype.addOperand.call(this, expr);
  23. };
  24. /** Takes a date and returns the second between 0 and 59, but can be 60 to account for leap seconds. **/
  25. proto.evaluate = function evaluate(doc){
  26. this.checkArgCount(1);
  27. var date = this.operands[0].evaluate(doc);
  28. return date.getSeconds(); //TODO: incorrect for last second of leap year, need to fix...
  29. // currently leap seconds are unsupported in v8
  30. // http://code.google.com/p/v8/issues/detail?id=1944
  31. };
  32. return klass;
  33. })();