Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/external_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ cass_int64_t cass_time_from_epoch(cass_int64_t epoch_secs) {
}

cass_int64_t cass_date_time_to_epoch(cass_uint32_t date, cass_int64_t time) {
return (date - CASS_DATE_EPOCH) * NUM_SECONDS_PER_DAY +
return (static_cast<cass_uint64_t>(date) - CASS_DATE_EPOCH) * NUM_SECONDS_PER_DAY +
time / CASS_TIME_NANOSECONDS_PER_SECOND;
}

Expand Down
15 changes: 12 additions & 3 deletions test/unit_tests/src/test_date_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <boost/test/unit_test.hpp>
#include <time.h>

#define CASS_DATE_EPOCH 2147483648U

BOOST_AUTO_TEST_SUITE(date_time)

BOOST_AUTO_TEST_CASE(simple)
Expand All @@ -35,9 +37,9 @@ BOOST_AUTO_TEST_CASE(simple)

BOOST_AUTO_TEST_CASE(date)
{
BOOST_CHECK(cass_date_from_epoch(0) ==2147483648u);
BOOST_CHECK(cass_date_from_epoch(24 * 3600) ==2147483649u);
BOOST_CHECK(cass_date_from_epoch(2 * 24 * 3600) ==2147483650u);
BOOST_CHECK_EQUAL(cass_date_from_epoch(0), CASS_DATE_EPOCH);
BOOST_CHECK_EQUAL(cass_date_from_epoch(24 * 3600), CASS_DATE_EPOCH + 1);
BOOST_CHECK_EQUAL(cass_date_from_epoch(2 * 24 * 3600), CASS_DATE_EPOCH + 2);
}

BOOST_AUTO_TEST_CASE(time)
Expand All @@ -49,4 +51,11 @@ BOOST_AUTO_TEST_CASE(time)
BOOST_CHECK(actual == expected);
}

BOOST_AUTO_TEST_CASE(date_time_to_epoc)
{
BOOST_CHECK_EQUAL(cass_date_time_to_epoch(CASS_DATE_EPOCH, 0), 0L); // Epoch
BOOST_CHECK_EQUAL(cass_date_time_to_epoch(CASS_DATE_EPOCH - 1, 0), -24L * 3600L); // Epoch - 1 day
BOOST_CHECK_EQUAL(cass_date_time_to_epoch(CASS_DATE_EPOCH + 1, 0), 24L * 3600L); // Epoch + 1 day
}

BOOST_AUTO_TEST_SUITE_END()