Просмотр исходного кода

REFS DEVOPS-272 Added v2.5 compatibility

David Aebersold 12 лет назад
Родитель
Сommit
ab039b3dd2
1 измененных файлов с 9 добавлено и 10 удалено
  1. 9 10
      lib/pipeline/expressions/WeekExpression.js

+ 9 - 10
lib/pipeline/expressions/WeekExpression.js

@@ -2,7 +2,7 @@
 
 
 /** 
 /** 
  * A $week pipeline expression.
  * A $week pipeline expression.
- * @see evaluate 
+ * @see evaluateInternal 
  * @class WeekExpression
  * @class WeekExpression
  * @namespace mungedb-aggregate.pipeline.expressions
  * @namespace mungedb-aggregate.pipeline.expressions
  * @module mungedb-aggregate
  * @module mungedb-aggregate
@@ -15,28 +15,24 @@ var WeekExpression = module.exports = function WeekExpression(){
 
 
 // DEPENDENCIES
 // DEPENDENCIES
 var Value = require("../Value"),
 var Value = require("../Value"),
-	DayOfYearExpression = require("./DayOfYearExpression");
+	DayOfYearExpression = require("./DayOfYearExpression"),
+	Expression = require("./Expression");
 
 
 // PROTOTYPE MEMBERS
 // PROTOTYPE MEMBERS
 proto.getOpName = function getOpName(){
 proto.getOpName = function getOpName(){
 	return "$week";
 	return "$week";
 };
 };
 
 
-proto.addOperand = function addOperand(expr) {
-	this.checkArgLimit(1);
-	base.prototype.addOperand.call(this, expr);
-};
-
 /** 
 /** 
  * Takes a date and returns the week of the year as a number between 0 and 53. 
  * Takes a date and returns the week of the year as a number between 0 and 53. 
  * Weeks begin on Sundays, and week 1 begins with the first Sunday of the year. 
  * Weeks begin on Sundays, and week 1 begins with the first Sunday of the year. 
  * Days preceding the first Sunday of the year are in week 0. 
  * Days preceding the first Sunday of the year are in week 0. 
  * This behavior is the same as the “%U” operator to the strftime standard library function.
  * This behavior is the same as the “%U” operator to the strftime standard library function.
- * @method evaluate
+ * @method evaluateInternal
  **/
  **/
-proto.evaluate = function evaluate(doc) {
+proto.evaluateInternal = function evaluateInternal(doc) {
 	this.checkArgCount(1);
 	this.checkArgCount(1);
-	var date = this.operands[0].evaluate(doc),
+	var date = this.operands[0].evaluateInternal(doc),
 		dayOfWeek = date.getUTCDay(),
 		dayOfWeek = date.getUTCDay(),
 		dayOfYear = DayOfYearExpression.getDateDayOfYear(date),
 		dayOfYear = DayOfYearExpression.getDateDayOfYear(date),
 		prevSundayDayOfYear = dayOfYear - dayOfWeek,	// may be negative
 		prevSundayDayOfYear = dayOfYear - dayOfWeek,	// may be negative
@@ -44,3 +40,6 @@ proto.evaluate = function evaluate(doc) {
 	// Return the zero based index of the week of the next sunday, equal to the one based index of the week of the previous sunday, which is to be returned.
 	// Return the zero based index of the week of the next sunday, equal to the one based index of the week of the previous sunday, which is to be returned.
 	return (nextSundayDayOfYear / 7) | 0; // also, the `| 0` here truncates this so that we return an integer
 	return (nextSundayDayOfYear / 7) | 0; // also, the `| 0` here truncates this so that we return an integer
 };
 };
+
+/** Register Expression */
+Expression.registerExpression("$week",WeekExpression.parse);