Skip to content

Commit

Permalink
Merge branch 'version-0.1.6' of github.com:lnd3/ltools into version-0…
Browse files Browse the repository at this point in the history
….1.6
  • Loading branch information
linuscu committed Nov 9, 2024
2 parents f82ac7f + cdcc535 commit 3f8d98c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/logging/include/logging/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace string {
char mBuf[SIZE];
};

void init_timezone();
int32_t get_local_timezone();
int32_t get_local_daylight_savings(bool inHours = false);

Expand Down
23 changes: 21 additions & 2 deletions packages/logging/source/common/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
#include <cstring>
#include <iostream>
#include <time.h>
#include <atomic>
#include <time.h>

namespace {
constexpr size_t buffer_size = 1024;

std::atomic_bool timezoneInited = false;

std::mutex bufferMutex;
char buffer[buffer_size];

Expand All @@ -29,24 +33,39 @@ namespace {
namespace l {
namespace string {

void init_timezone() {
if (timezoneInited) {
return;
}
timezoneInited = true;

#ifdef WIN32
_tzset();
#else
tzset();
#endif
}

int32_t get_local_timezone() {
init_timezone();
#ifdef WIN32
long time;
auto res = _get_timezone(&time);
ASSERT(res == 0);
#else
auto time = __timezone;
auto time = timezone;
#endif
return static_cast<int32_t>(- time); // negate since timezone is how to get utc time from local time (local time - utc time)
}

int32_t get_local_daylight_savings(bool inHours) {
init_timezone();
#ifdef WIN32
int time;
auto res = _get_daylight(&time);
ASSERT(res == 0);
#else
auto time = __daylight;
auto time = daylight;
#endif
return static_cast<int32_t>(inHours ? time : time * 3600);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/serialization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set(deps
testing
)

bs_generate_package(serialization "tier1" "${deps}" "various")
bs_generate_package(serialization "tier1" "${deps}" "various;jsonxx")
39 changes: 39 additions & 0 deletions packages/serialization/tests/common/JsonxxTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "testing/Test.h"
#include "logging/Log.h"

#include "jsonxx/jsonxx.h"

#include <cstring>
#include <string>
#include <string_view>
#include <memory>
#include <iostream>

TEST(Jsonxx, Parse) {

std::stringstream stream;

char buf[200];

std::string s1("{\"e\":\"kline\",\"E\":1731096660008,\"s\":\"OPUSDT\",\"k\":{\"t\":1731096600000,\"T\":1731096659999,\"s\":\"OPUSDT\",\"i");
memcpy(buf, s1.c_str(), s1.size());
stream << std::string_view(buf, s1.size());

jsonxx::Object o;
TEST_FALSE(o.parse(stream), "");
stream.clear();
std::string s2("\":\"2\"}}");
memcpy(buf, s2.c_str(), s1.size());
stream << std::string_view(buf, s1.size());
TEST_FALSE(o.parse(stream), "");
stream.clear();

stream.seekg(0);
stream.seekp(0, std::ios_base::end);
stream << std::string_view(buf, s1.size());
TEST_TRUE(o.parse(stream), "");


return 0;
}

5 changes: 2 additions & 3 deletions packages/testing/tests/common/LoggingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ TEST(Logging, TimeConversions) {
auto time = l::string::convert_to_utc_time_from_local_time(localtime);
TEST_EQ(time, unixtime, "");
}
{
if (false) { // will not work around daylight savings switch so deactivate
auto unixtime = l::string::get_unix_epoch();
auto localtime = l::string::convert_to_local_time_from_utc_time(unixtime);
struct tm timeinfolocal;
Expand All @@ -154,8 +154,7 @@ TEST(Logging, TimeConversions) {
l::string::convert_to_local_tm_from_utc_time(unixtime, &timeinfo, true);
TEST_EQ(timeinfo.tm_hour, timeinfolocal.tm_hour, "");
}

{
if (false) { // will not work around daylight savings switch so deactivate
auto unixtime = l::string::get_unix_epoch();
int32_t fullDate[6];
l::string::to_local_time(unixtime, fullDate);
Expand Down

0 comments on commit 3f8d98c

Please sign in to comment.