summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/parse_zone_info.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/noPassthrough/parse_zone_info.js')
-rw-r--r--jstests/noPassthrough/parse_zone_info.js17
1 files changed, 16 insertions, 1 deletions
diff --git a/jstests/noPassthrough/parse_zone_info.js b/jstests/noPassthrough/parse_zone_info.js
index 9e9343e020f..c9836de08e3 100644
--- a/jstests/noPassthrough/parse_zone_info.js
+++ b/jstests/noPassthrough/parse_zone_info.js
@@ -1,4 +1,4 @@
-// Tests the parsing of the timeZoneInfo parameter.
+// Tests the parsing of the timeZoneInfo parameter and file use.
(function() {
// Test that a bad file causes startup to fail.
let conn = MongoRunner.runMongod({timeZoneInfo: "jstests/libs/config_files/bad_timezone_info"});
@@ -16,5 +16,20 @@ assert(rawMongoProgramOutput().includes("Error creating service context") ||
// Test that startup can succeed with a good file.
conn = MongoRunner.runMongod({timeZoneInfo: "jstests/libs/config_files/good_timezone_info"});
assert.neq(conn, null, "expected launching mongod with good timezone rules to succeed");
+
+// Test that can use file-provided timezones in an expression.
+const testDB = conn.getDB("test");
+const coll = testDB.parse_zone_info;
+assert.commandWorked(coll.insert({x: new Date()}));
+assert.doesNotThrow(
+ () => coll.aggregate([{$set: {x_parts: {$dateToParts: {date: "$x", timezone: "GMT"}}}}]));
+assert.doesNotThrow(
+ () => coll.aggregate(
+ [{$set: {x_parts: {$dateToParts: {date: "$x", timezone: "America/Sao_Paulo"}}}}]));
+
+// Confirm that attempt to use a non-existent timezone in an expression fails.
+const err = assert.throws(
+ () => coll.aggregate([{$set: {x_parts: {$dateToParts: {date: "$x", timezone: "Unknown"}}}}]));
+assert.eq(err.code, 40485);
MongoRunner.stopMongod(conn);
}());