Skip to content

Commit

Permalink
Code review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenick committed Sep 9, 2015
1 parent 8151556 commit b94a1ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
11 changes: 5 additions & 6 deletions include/cassandra.h
Original file line number Diff line number Diff line change
Expand Up @@ -6400,9 6400,9 @@ cass_inet_from_string_n(const char* str,
************************************************************************************/

/**
* Converts Epoch time in seconds to the Cassandra "date" type. The "date" type
* represents the number of days since the Epoch with the Epoch centered at the
* value 2^31.
* Converts a unix timestamp (in seconds) to the Cassandra "date" type. The "date" type
* represents the number of days since the Epoch (1970-01-01) with the Epoch centered at
* the value 2^31.
*
* @param[in] time
* @return the number of days since the date -5877641-06-23
Expand All @@ -6411,9 6411,8 @@ CASS_EXPORT cass_uint32_t
cass_date_from_epoch(cass_int64_t epoch_secs);

/**
* Converts Epoch time in seconds to the Cassandra "time" type. The "time" type
* represents the number of nanoseconds since midnight (range 0 to
* 86399999999999).
* Converts a unix timestamp (in seconds) to the Cassandra "time" type. The "time" type
* represents the number of nanoseconds since midnight (range 0 to 86399999999999).
*
* @param[in] time
* @return nanoseconds since midnight
Expand Down
10 changes: 4 additions & 6 deletions src/external_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 16,9 @@

#include "external_types.hpp"

#include <limits>
#include <time.h>
#include <uv.h>

#define CASS_DATE_NUM_SECONDS_PER_DAY (24U * 60U * 60U)
#define NUM_SECONDS_PER_DAY (24U * 60U * 60U)
#define CASS_DATE_EPOCH 2147483648U // 2^31
#define CASS_TIME_NANOSECONDS_PER_SECOND 1000000000LL

Expand Down Expand Up @@ -129,16 127,16 @@ CassError cass_inet_from_string_n(const char* str,
}

cass_uint32_t cass_date_from_epoch(cass_int64_t epoch_secs) {
return (epoch_secs / CASS_DATE_NUM_SECONDS_PER_DAY) CASS_DATE_EPOCH;
return (epoch_secs / NUM_SECONDS_PER_DAY) CASS_DATE_EPOCH;
}

cass_int64_t cass_time_from_epoch(cass_int64_t epoch_secs) {
return CASS_TIME_NANOSECONDS_PER_SECOND *
(epoch_secs % CASS_DATE_NUM_SECONDS_PER_DAY);
(epoch_secs % NUM_SECONDS_PER_DAY);
}

cass_int64_t cass_date_time_to_epoch(cass_uint32_t date, cass_int64_t time) {
return (date - CASS_DATE_EPOCH) * CASS_DATE_NUM_SECONDS_PER_DAY
return (date - CASS_DATE_EPOCH) * NUM_SECONDS_PER_DAY
time / CASS_TIME_NANOSECONDS_PER_SECOND;
}

Expand Down

0 comments on commit b94a1ff

Please sign in to comment.