Skip to content

Commit

Permalink
Update timestamp calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
viper4gh committed Jan 21, 2022
1 parent 312f138 commit 4a52b5a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion SharedMemoryRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ std::string SharedMemoryRenderer::render(const SharedMemory* sharedData, std::st
printf("timespec_get failed!\n");
}
uint64_t cur_time = 1000000000 * ts.tv_sec + ts.tv_nsec;
uint64_t cur_time_ms = (uint64_t) round((double)cur_time / 1000000); // cast to double first for correct rounding and cast to uint64_t back
//printf("cur Time: %llu , cur Time ms: %llu\n", cur_time, cur_time_ms);

// if the URL parameter includes "formatted=true" then generate a formatted browser output
if (Utils::contains(queryString, "formatted=true")) {
Expand Down Expand Up @@ -350,7 +352,8 @@ std::string SharedMemoryRenderer::render(const SharedMemory* sharedData, std::st
renderWeather(ss, sharedData);
skipSeparator = false;
}
ss << "," << nl << tab << "\"timestamp\":" << cur_time / 100000; // curtime in milliseconds + 1 digit - for milliseconds divide it by 10 (division of integers truncates the value instead of rounding, in result 1 digit more for precision)
//ss << "," << nl << tab << "\"timestamp\":" << cur_time / 100000; // curtime in milliseconds + 1 digit - for milliseconds divide it by 10 (division of integers truncates the value instead of rounding, in result 1 digit more for precision)
ss << "," << nl << tab << "\"timestamp\":" << cur_time_ms;
ss << nl << "}";

return ss.str();
Expand Down

0 comments on commit 4a52b5a

Please sign in to comment.