diff options
author | Mathias Stearn <mathias@10gen.com> | 2012-08-02 13:39:46 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2012-08-02 17:47:59 -0400 |
commit | e9bfafe93d0509a46f43e1ee8d8cc0a2bb64bd53 (patch) | |
tree | eecef3279cf003b5075b6d3775523fbece1882d0 | |
parent | b9eacf04d88dfa461497ef9dcf2acc771f2ae209 (diff) | |
download | mongo-e9bfafe93d0509a46f43e1ee8d8cc0a2bb64bd53.tar.gz |
SERVER-6679 Value::coerceToString uses UTC ISODate format for dates
-rw-r--r-- | jstests/aggregation/bugs/server6189.js | 4 | ||||
-rw-r--r-- | src/mongo/db/pipeline/value.cpp | 10 |
2 files changed, 11 insertions, 3 deletions
diff --git a/jstests/aggregation/bugs/server6189.js b/jstests/aggregation/bugs/server6189.js index 71acae1062a..c9c7b59aaad 100644 --- a/jstests/aggregation/bugs/server6189.js +++ b/jstests/aggregation/bugs/server6189.js @@ -15,7 +15,7 @@ function test(date, testSynthetics) { //, millisecond:{ $millisecond: '$date' } // server-6666 // $substr will call coerceToString - //, string: {$substr: ['$date', 0,1000]} // server-6679 + , string: {$substr: ['$date', 0,1000]} }} ); if (date.getUTCFullYear() < 1970 && _isWindows() && result.code == 16422) { @@ -38,7 +38,7 @@ function test(date, testSynthetics) { , minute: date.getUTCMinutes() , second: date.getUTCSeconds() //, millisecond: date.getUTCMilliseconds() // server-6666 - //, string: date.tojson().split('"')[1] // server-6679 + , string: date.tojson().slice(9,28) } ); if (testSynthetics) { diff --git a/src/mongo/db/pipeline/value.cpp b/src/mongo/db/pipeline/value.cpp index 5447820370a..ff75022a4fb 100644 --- a/src/mongo/db/pipeline/value.cpp +++ b/src/mongo/db/pipeline/value.cpp @@ -668,6 +668,14 @@ namespace mongo { return out; } + static string tmToISODateString(const tm& time) { + char buf[128]; + size_t len = strftime(buf, 128, "%Y-%m-%dT%H:%M:%S", &time); + verify(len > 0); + verify(len < 128); + return buf; + } + string Value::coerceToString() const { stringstream ss; switch(type) { @@ -691,7 +699,7 @@ namespace mongo { return ss.str(); case Date: - return time_t_to_String(coerceToTimeT()); + return tmToISODateString(coerceToTm()); case jstNULL: case Undefined: |