SecondExpression.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. /**
  3. * An $second pipeline expression.
  4. * @see evaluateInternal
  5. * @class SecondExpression
  6. * @namespace mungedb-aggregate.pipeline.expressions
  7. * @module mungedb-aggregate
  8. * @constructor
  9. **/
  10. var SecondExpression = module.exports = function SecondExpression() {
  11. base.call(this);
  12. }, klass = SecondExpression,
  13. FixedArityExpression = require("./FixedArityExpressionT")(klass, 1),
  14. base = FixedArityExpression,
  15. proto = klass.prototype = Object.create(base.prototype, {
  16. constructor: {
  17. value: klass
  18. }
  19. });
  20. // DEPENDENCIES
  21. var Expression = require("./Expression");
  22. // PROTOTYPE MEMBERS
  23. proto.getOpName = function getOpName() {
  24. return "$second";
  25. };
  26. /**
  27. * Takes a date and returns the second between 0 and 59, but can be 60 to account for leap seconds.
  28. * @method evaluateInternal
  29. **/
  30. proto.evaluateInternal = function evaluateInternal(vars) {
  31. var date = this.operands[0].evaluateInternal(vars);
  32. return date.getUTCSeconds(); //TODO: incorrect for last second of leap year, need to fix...
  33. // currently leap seconds are unsupported in v8
  34. // http://code.google.com/p/v8/issues/detail?id=1944
  35. };
  36. /** Register Expression */
  37. Expression.registerExpression("$second", base.parse);