summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/datetime/date_time_support.cpp
diff options
context:
space:
mode:
authorNick Zolnierz <nicholas.zolnierz@mongodb.com>2018-02-01 11:12:12 -0500
committerNick Zolnierz <nicholas.zolnierz@mongodb.com>2018-02-09 10:12:05 -0500
commit695d94255348302be2d804e2187eb61e15cbb412 (patch)
tree6d0ab734ac26b158358ceb5fc9a42b7b0c3bb064 /src/mongo/db/query/datetime/date_time_support.cpp
parentd1b2515a2d7dd4a22222de7d8905d6dc6b1ab1be (diff)
downloadmongo-695d94255348302be2d804e2187eb61e15cbb412.tar.gz
SERVER-30523: dateFromParts should not reject out-of-range numbers for date/time properties
Diffstat (limited to 'src/mongo/db/query/datetime/date_time_support.cpp')
-rw-r--r--src/mongo/db/query/datetime/date_time_support.cpp34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/mongo/db/query/datetime/date_time_support.cpp b/src/mongo/db/query/datetime/date_time_support.cpp
index c41df5b28d6..c13bce509c4 100644
--- a/src/mongo/db/query/datetime/date_time_support.cpp
+++ b/src/mongo/db/query/datetime/date_time_support.cpp
@@ -47,9 +47,14 @@
namespace mongo {
namespace {
+
const auto getTimeZoneDatabase =
ServiceContext::declareDecoration<std::unique_ptr<TimeZoneDatabase>>();
+std::unique_ptr<_timelib_time, TimeZone::TimelibTimeDeleter> createTimelibTime() {
+ return std::unique_ptr<_timelib_time, TimeZone::TimelibTimeDeleter>(timelib_time_ctor());
+}
+
// Converts a date to a number of seconds, being careful to round appropriately for negative numbers
// of seconds.
long long seconds(Date_t date) {
@@ -373,9 +378,14 @@ void TimeZone::adjustTimeZone(timelib_time* timelibTime) const {
timelib_update_from_sse(timelibTime);
}
-Date_t TimeZone::createFromDateParts(
- int year, int month, int day, int hour, int minute, int second, int millisecond) const {
- std::unique_ptr<timelib_time, TimeZone::TimelibTimeDeleter> newTime(timelib_time_ctor());
+Date_t TimeZone::createFromDateParts(long long year,
+ long long month,
+ long long day,
+ long long hour,
+ long long minute,
+ long long second,
+ long long millisecond) const {
+ auto newTime = createTimelibTime();
newTime->y = year;
newTime->m = month;
@@ -393,14 +403,14 @@ Date_t TimeZone::createFromDateParts(
return returnValue;
}
-Date_t TimeZone::createFromIso8601DateParts(int isoYear,
- int isoWeekYear,
- int isoDayOfWeek,
- int hour,
- int minute,
- int second,
- int millisecond) const {
- std::unique_ptr<timelib_time, TimeZone::TimelibTimeDeleter> newTime(timelib_time_ctor());
+Date_t TimeZone::createFromIso8601DateParts(long long isoYear,
+ long long isoWeekYear,
+ long long isoDayOfWeek,
+ long long hour,
+ long long minute,
+ long long second,
+ long long millisecond) const {
+ auto newTime = createTimelibTime();
timelib_date_from_isodate(
isoYear, isoWeekYear, isoDayOfWeek, &newTime->y, &newTime->m, &newTime->d);
@@ -468,7 +478,7 @@ void TimeZone::TimelibTimeDeleter::operator()(timelib_time* time) {
std::unique_ptr<timelib_time, TimeZone::TimelibTimeDeleter> TimeZone::getTimelibTime(
Date_t date) const {
- std::unique_ptr<timelib_time, TimeZone::TimelibTimeDeleter> time(timelib_time_ctor());
+ auto time = createTimelibTime();
timelib_unixtime2gmt(time.get(), seconds(date));
adjustTimeZone(time.get());