diff --git a/src/common/types/date_t.cpp b/src/common/types/date_t.cpp index 3fd7561cfe6..b1d2fe9b162 100644 --- a/src/common/types/date_t.cpp +++ b/src/common/types/date_t.cpp @@ -390,13 +390,13 @@ int32_t Date::monthDays(int32_t year, int32_t month) { return Date::isLeapYear(year) ? Date::LEAP_DAYS[month] : Date::NORMAL_DAYS[month]; } -std::string Date::getDayName(date_t& date) { +std::string Date::getDayName(date_t date) { std::string dayNames[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; return dayNames[(date.days < 0 ? 7 - ((-date.days + 3) % 7) : ((date.days + 3) % 7) + 1) % 7]; } -std::string Date::getMonthName(date_t& date) { +std::string Date::getMonthName(date_t date) { std::string monthNames[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; int32_t year = 0, month = 0, day = 0; @@ -404,7 +404,7 @@ std::string Date::getMonthName(date_t& date) { return monthNames[month - 1]; } -date_t Date::getLastDay(date_t& date) { +date_t Date::getLastDay(date_t date) { int32_t year = 0, month = 0, day = 0; Date::convert(date, year, month, day); year += (month / 12); @@ -413,7 +413,7 @@ date_t Date::getLastDay(date_t& date) { return Date::fromDate(year, month, 1) - 1; } -int32_t Date::getDatePart(DatePartSpecifier specifier, date_t& date) { +int32_t Date::getDatePart(DatePartSpecifier specifier, date_t date) { int32_t year = 0, month = 0, day = 0; Date::convert(date, year, month, day); switch (specifier) { @@ -446,7 +446,7 @@ int32_t Date::getDatePart(DatePartSpecifier specifier, date_t& date) { } } -date_t Date::trunc(DatePartSpecifier specifier, date_t& date) { +date_t Date::trunc(DatePartSpecifier specifier, date_t date) { switch (specifier) { case DatePartSpecifier::YEAR: return Date::fromDate(Date::getDatePart(DatePartSpecifier::YEAR, date), 1 /* month */, diff --git a/src/common/types/interval_t.cpp b/src/common/types/interval_t.cpp index 9d9736372a8..cc66f7d5a77 100644 --- a/src/common/types/interval_t.cpp +++ b/src/common/types/interval_t.cpp @@ -420,7 +420,7 @@ void Interval::tryGetDatePartSpecifier(std::string specifier, DatePartSpecifier& } } -int32_t Interval::getIntervalPart(DatePartSpecifier specifier, interval_t& interval) { +int32_t Interval::getIntervalPart(DatePartSpecifier specifier, interval_t interval) { switch (specifier) { case DatePartSpecifier::YEAR: return interval.months / Interval::MONTHS_PER_YEAR; diff --git a/src/common/types/timestamp_t.cpp b/src/common/types/timestamp_t.cpp index 05418236f6a..d466c37171a 100644 --- a/src/common/types/timestamp_t.cpp +++ b/src/common/types/timestamp_t.cpp @@ -282,7 +282,7 @@ timestamp_t Timestamp::fromEpochNanoSeconds(int64_t ns) { return fromEpochMicroSeconds(ns / 1000); } -int32_t Timestamp::getTimestampPart(DatePartSpecifier specifier, timestamp_t& timestamp) { +int32_t Timestamp::getTimestampPart(DatePartSpecifier specifier, timestamp_t timestamp) { switch (specifier) { case DatePartSpecifier::MICROSECOND: return getTime(timestamp).micros % Interval::MICROS_PER_MINUTE; @@ -303,7 +303,7 @@ int32_t Timestamp::getTimestampPart(DatePartSpecifier specifier, timestamp_t& ti } } -timestamp_t Timestamp::trunc(DatePartSpecifier specifier, timestamp_t& timestamp) { +timestamp_t Timestamp::trunc(DatePartSpecifier specifier, timestamp_t timestamp) { int32_t hour = 0, min = 0, sec = 0, micros = 0; date_t date; dtime_t time; diff --git a/src/include/common/types/date_t.h b/src/include/common/types/date_t.h index 576a3c623cd..5e92995a44c 100644 --- a/src/include/common/types/date_t.h +++ b/src/include/common/types/date_t.h @@ -99,15 +99,15 @@ class Date { KUZU_API static int32_t monthDays(int32_t year, int32_t month); - KUZU_API static std::string getDayName(date_t& date); + KUZU_API static std::string getDayName(date_t date); - KUZU_API static std::string getMonthName(date_t& date); + KUZU_API static std::string getMonthName(date_t date); - KUZU_API static date_t getLastDay(date_t& date); + KUZU_API static date_t getLastDay(date_t date); - KUZU_API static int32_t getDatePart(DatePartSpecifier specifier, date_t& date); + KUZU_API static int32_t getDatePart(DatePartSpecifier specifier, date_t date); - KUZU_API static date_t trunc(DatePartSpecifier specifier, date_t& date); + KUZU_API static date_t trunc(DatePartSpecifier specifier, date_t date); KUZU_API static int64_t getEpochNanoSeconds(const date_t& date); diff --git a/src/include/common/types/interval_t.h b/src/include/common/types/interval_t.h index e0d6da7670f..01b93aae2b3 100644 --- a/src/include/common/types/interval_t.h +++ b/src/include/common/types/interval_t.h @@ -105,7 +105,7 @@ class Interval { KUZU_API static void normalizeIntervalEntries(interval_t input, int64_t& months, int64_t& days, int64_t& micros); KUZU_API static void tryGetDatePartSpecifier(std::string specifier, DatePartSpecifier& result); - KUZU_API static int32_t getIntervalPart(DatePartSpecifier specifier, interval_t& timestamp); + KUZU_API static int32_t getIntervalPart(DatePartSpecifier specifier, interval_t timestamp); KUZU_API static int64_t getMicro(const interval_t& val); KUZU_API static int64_t getNanoseconds(const interval_t& val); KUZU_API static const regex::RE2& regexPattern1(); diff --git a/src/include/common/types/timestamp_t.h b/src/include/common/types/timestamp_t.h index 790c99eaaaf..5af76fed99b 100644 --- a/src/include/common/types/timestamp_t.h +++ b/src/include/common/types/timestamp_t.h @@ -93,9 +93,9 @@ class Timestamp { // Create a Timestamp object from the specified epochNs. KUZU_API static timestamp_t fromEpochNanoSeconds(int64_t ns); - KUZU_API static int32_t getTimestampPart(DatePartSpecifier specifier, timestamp_t& timestamp); + KUZU_API static int32_t getTimestampPart(DatePartSpecifier specifier, timestamp_t timestamp); - KUZU_API static timestamp_t trunc(DatePartSpecifier specifier, timestamp_t& date); + KUZU_API static timestamp_t trunc(DatePartSpecifier specifier, timestamp_t date); KUZU_API static int64_t getEpochNanoSeconds(const timestamp_t& timestamp); diff --git a/test/test_files/function/date.test b/test/test_files/function/date.test index a1bb4fe865e..36cf49bf8b7 100644 --- a/test/test_files/function/date.test +++ b/test/test_files/function/date.test @@ -133,7 +133,7 @@ October October November --LOG StructuredDateLastDayFuncTest +-LOG DateLastDayFuncTest -STATEMENT MATCH (p:person) RETURN last_day(p.birthdate) ---- 8 1900-01-31 @@ -145,6 +145,20 @@ November 1980-10-31 1990-11-30 +-LOG LastDayInFilter +-STATEMENT MATCH (p:person) WHERE last_day(p.birthdate) > date('1940-06-30') RETURN p.birthdate +---- 5 +1950-07-23 +1980-10-26 +1980-10-26 +1980-10-26 +1990-11-27 + +-LOG DatePartWithFilterTest +-STATEMENT MATCH (p:person) WHERE date_part("year", p.birthdate) > 1940 and date_part("year", p.birthdate) < 1976 RETURN p.fName +---- 1 +Dan + -LOG StructuredDateExtractYearFuncTest -STATEMENT MATCH (p:person) RETURN date_part("year", p.birthdate) ---- 8 @@ -325,7 +339,7 @@ November 1980-10-01 1990-10-01 --LOG StructuredDateTruncSecondFuncTest +-LOG DateTruncSecondFuncTest -STATEMENT MATCH (p:person) RETURN date_trunc("second", p.birthdate) ---- 8 1900-01-01 @@ -337,6 +351,16 @@ November 1980-10-26 1990-11-27 +-LOG DateTruncInFilter +-STATEMENT MATCH (p:person) where date_trunc("second", p.birthdate) <> date('1900-01-01') RETURN p.birthdate +---- 6 +1940-06-22 +1950-07-23 +1980-10-26 +1980-10-26 +1980-10-26 +1990-11-27 + -LOG StructuredDateGreatestFuncTest -STATEMENT MATCH (p:person) RETURN greatest(p.birthdate, date("1980-10-02")) ---- 8