summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorDavid Storch <david.storch@mongodb.com>2019-12-13 14:38:00 +0000
committerevergreen <evergreen@mongodb.com>2019-12-13 14:38:00 +0000
commit8c4c6cc2b5e3818873b9dadcedd029839b5dc550 (patch)
tree3b38af7a415604fe92cd9031fbf707f7a519885e /jstests
parent97a3e24c6bb07ae3a108c0eeb1d00ba36332b7d6 (diff)
downloadmongo-8c4c6cc2b5e3818873b9dadcedd029839b5dc550.tar.gz
SERVER-44568 Update server's embedded time zone rules to version 2019c.
This applies commit 7100439d476a615466bac87e89eea45ca9ec55fc from the upstream third party repository, derickr/timelib. It also adds a test to ensure that the latest time zone rules are now respected by default (in particular, that the abolition of daylight savings time in Brazil is accounted for). 2019c is the most recent time zone database as of this writing, but the latest version can always be found at iana.org/time-zones. (cherry picked from commit 317684a1dad2c629a9a8bdc6bf37639d72a6aae0)
Diffstat (limited to 'jstests')
-rw-r--r--jstests/aggregation/expressions/date_expressions_with_timezones.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/jstests/aggregation/expressions/date_expressions_with_timezones.js b/jstests/aggregation/expressions/date_expressions_with_timezones.js
index 83f7488f26c..a56d024b1f4 100644
--- a/jstests/aggregation/expressions/date_expressions_with_timezones.js
+++ b/jstests/aggregation/expressions/date_expressions_with_timezones.js
@@ -80,4 +80,43 @@
{$sort: {"_id.year": 1, "_id.month": 1, "_id.day": 1}}
])
.toArray());
+
+ assert(coll.drop());
+ assert.commandWorked(coll.insert({}));
+
+ // Given a date, executes an aggregation command which requires the server to convert this date
+ // to its parts in a timezone-aware fashion. Returns the resulting document containing the date
+ // parts.
+ function runDateToPartsExpression(inputDate, timezone) {
+ const results =
+ coll.aggregate([{
+ $project:
+ {_id: 0, out: {$dateToParts: {date: inputDate, timezone: timezone}}}
+ }])
+ .toArray();
+ assert.eq(results.length, 1, results);
+ return results[0].out;
+ }
+
+ // Test that the time zone info is up to date as of the 2019c IANA tz db release. In 2019,
+ // Brazil abolished its daylight savings time. In recent years prior to 2019, Brazil would
+ // change from UTC-3 to UTC-2, typically starting in October or November and ending in February.
+ // Here we test that dates in December and January use UTC-2 in 2017 and 2018, but use UTC-3 in
+ // 2019 and 2020 for the Sao Paulo timezone.
+ assert.eq({year: 2017, month: 12, day: 15, hour: 8, minute: 0, second: 0, millisecond: 0},
+ runDateToPartsExpression(ISODate("2017-12-15T10:00:00.000Z"), "America/Sao_Paulo"));
+ assert.eq({year: 2018, month: 1, day: 15, hour: 8, minute: 0, second: 0, millisecond: 0},
+ runDateToPartsExpression(ISODate("2018-01-15T10:00:00.000Z"), "America/Sao_Paulo"));
+ assert.eq({year: 2018, month: 12, day: 15, hour: 8, minute: 0, second: 0, millisecond: 0},
+ runDateToPartsExpression(ISODate("2018-12-15T10:00:00.000Z"), "America/Sao_Paulo"));
+ assert.eq({year: 2019, month: 1, day: 15, hour: 8, minute: 0, second: 0, millisecond: 0},
+ runDateToPartsExpression(ISODate("2019-01-15T10:00:00.000Z"), "America/Sao_Paulo"));
+ assert.eq({year: 2019, month: 12, day: 15, hour: 7, minute: 0, second: 0, millisecond: 0},
+ runDateToPartsExpression(ISODate("2019-12-15T10:00:00.000Z"), "America/Sao_Paulo"));
+ assert.eq({year: 2020, month: 1, day: 15, hour: 7, minute: 0, second: 0, millisecond: 0},
+ runDateToPartsExpression(ISODate("2020-01-15T10:00:00.000Z"), "America/Sao_Paulo"));
+ assert.eq({year: 2020, month: 12, day: 15, hour: 7, minute: 0, second: 0, millisecond: 0},
+ runDateToPartsExpression(ISODate("2020-12-15T10:00:00.000Z"), "America/Sao_Paulo"));
+ assert.eq({year: 2021, month: 1, day: 15, hour: 7, minute: 0, second: 0, millisecond: 0},
+ runDateToPartsExpression(ISODate("2021-01-15T10:00:00.000Z"), "America/Sao_Paulo"));
})();