|
|
@@ -8,8 +8,8 @@
|
|
|
* @constructor
|
|
|
**/
|
|
|
var DateToStringExpression = module.exports = function DateToStringExpression(format, date) {
|
|
|
- //this.nargs = 1;
|
|
|
- //base.call(this);
|
|
|
+ //this.nargs = 1;
|
|
|
+ //base.call(this);
|
|
|
this._format = format;
|
|
|
this._date = date;
|
|
|
}, klass = DateToStringExpression, base = require("./Expression"), proto = klass.prototype = Object.create(base.prototype, {constructor: {value: klass}});
|
|
|
@@ -92,7 +92,7 @@ klass.validateFormat = function validateFormat(format) {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-klass.formatDate = function formatDate(format, tm, date) {
|
|
|
+klass.formatDate = function formatDate(format, date) {
|
|
|
var chars = format.split(''),
|
|
|
formatted = "";
|
|
|
for (it = 0; it < chars.length; it++) {
|
|
|
@@ -108,38 +108,38 @@ klass.formatDate = function formatDate(format, tm, date) {
|
|
|
formatted = formatted + it;
|
|
|
break;
|
|
|
case 'Y':
|
|
|
- var year = YearExpression.extract(tm);
|
|
|
+ var year = YearExpression.extract(date);
|
|
|
if (year < 0 || year > 9999) {
|
|
|
throw new Error("$dateToString is only defined on year 0-9999. Tried to use year " + year + ": 18537");
|
|
|
}
|
|
|
insertPadded(formatted, year, 4);
|
|
|
break;
|
|
|
case 'm':
|
|
|
- insertPadded(formatted, MonthExpression.extract(tm), 2);
|
|
|
+ insertPadded(formatted, MonthExpression.extract(date), 2);
|
|
|
break;
|
|
|
case 'd': // Day of month
|
|
|
- insertPadded(formatted, DayOfMonthExpression.extract(tm), 2);
|
|
|
+ insertPadded(formatted, DayOfMonthExpression.extract(date), 2);
|
|
|
break;
|
|
|
case 'H': // Hour
|
|
|
- insertPadded(formatted, HourExpression.extract(tm), 2);
|
|
|
+ insertPadded(formatted, HourExpression.extract(date), 2);
|
|
|
break;
|
|
|
case 'M': // Minute
|
|
|
- insertPadded(formatted, MinuteExpression.extract(tm), 2);
|
|
|
+ insertPadded(formatted, MinuteExpression.extract(date), 2);
|
|
|
break;
|
|
|
case 'S': // Second
|
|
|
- insertPadded(formatted, SecondExpression.extract(tm), 2);
|
|
|
+ insertPadded(formatted, SecondExpression.extract(date), 2);
|
|
|
break;
|
|
|
case 'L': // Millisecond
|
|
|
insertPadded(formatted, MillisecondExpression.extract(date), 3);
|
|
|
break;
|
|
|
case 'j': // Day of year
|
|
|
- insertPadded(formatted, DayOfYearExpression.extract(tm), 3);
|
|
|
+ insertPadded(formatted, DayOfYearExpression.extract(date), 3);
|
|
|
break;
|
|
|
case 'w': // Day of week
|
|
|
- insertPadded(formatted, DayOfWeekExpression.extract(tm), 1);
|
|
|
+ insertPadded(formatted, DayOfWeekExpression.extract(date), 1);
|
|
|
break;
|
|
|
case 'U': // Week
|
|
|
- insertPadded(formatted, WeekExpression.extract(tm), 2);
|
|
|
+ insertPadded(formatted, WeekExpression.extract(date), 2);
|
|
|
break;
|
|
|
default:
|
|
|
//NOTE: DEVIATION FROM MONGO: invariant(false)
|
|
|
@@ -175,6 +175,7 @@ klass.insertPadded = function insertPadded(sb, number, spaces) {
|
|
|
|
|
|
klass.pad = function pad(num, size) {
|
|
|
var s = num+"";
|
|
|
+ var s = 5;
|
|
|
while (s.length < size) s = "0" + s;
|
|
|
return s;
|
|
|
}
|
|
|
@@ -185,14 +186,14 @@ proto.getOpName = function getOpName() {
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Takes a date and returns the day of the month as a number between 1 and 31.
|
|
|
+ * Takes a date and returns a formatted string for that date
|
|
|
* @method evaluate
|
|
|
**/
|
|
|
proto.evaluateInternal = function evaluateInternal(vars) {
|
|
|
var date = this.operands[0].evaluateInternal(vars);
|
|
|
|
|
|
- //NOTE: DEVIATION FROM MONGO: need to return a Value object. Our Value class only consists of static helpers at the moment. We need a value instance to be consistent.
|
|
|
- return ;
|
|
|
+ if (!date || date == null)
|
|
|
+ return formatDate(this._format, date);
|
|
|
};
|
|
|
|
|
|
proto.addDependencies = function addDependencies(depsTracker) {
|