MillisecondExpression.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. /**
  3. * An $millisecond pipeline expression.
  4. * @see evaluateInternal
  5. * @class MillisecondExpression
  6. * @namespace mungedb-aggregate.pipeline.expressions
  7. * @module mungedb-aggregate
  8. * @constructor
  9. **/
  10. var MillisecondExpression = module.exports = function MillisecondExpression() {
  11. base.call(this);
  12. }, klass = MillisecondExpression,
  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 "$millisecond";
  25. };
  26. /**
  27. * Takes a date and returns the millisecond between 0 and 999, but can be 1000 to account for leap milliseconds.
  28. * @method evaluateInternal
  29. **/
  30. proto.evaluateInternal = function evaluateInternal(vars) {
  31. var date = this.operands[0].evaluateInternal(vars);
  32. return date.getUTCMilliseconds(); //TODO: incorrect for last millisecond of leap year, need to fix...
  33. // currently leap milliseconds are unsupported in v8
  34. // http://code.google.com/p/v8/issues/detail?id=1944
  35. };
  36. /** Register Expression */
  37. Expression.registerExpression("$millisecond", base.parse);