Commit 74e024b9 authored by Alexander Lapshin's avatar Alexander Lapshin

+ get_ts, json loading data types, refactoring

parent c309791e
This diff is collapsed.
...@@ -112,3 +112,38 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<TimeJ ...@@ -112,3 +112,38 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<TimeJ
return true; return true;
} }
static bool loadjson(const std::map<std::string, std::string>& parent, const std::string& key, svalue<TimeJD>& value, const bool exist = true)
{
std::map<std::string, std::string>::const_iterator itr;
bool* loaded = nullptr;
if (!extract_value(parent, key, exist, loaded, itr)) {
return false;
}
value = StrToDate(itr->second);
return true;
}
static bool loadjson(const std::map<std::string, std::string>& parent, const std::string& key, TimeJD& value, const bool exist = true, bool* loaded = nullptr)
{
std::map<std::string, std::string>::const_iterator itr;
if (!extract_value(parent, key, exist, loaded, itr)) {
return false;
}
const std::string& str = itr->second;
if (str.empty() && !exist) {
if (loaded) {
*loaded = false;
}
return false;
}
value = StrToDate(str);
return true;
}
...@@ -81,4 +81,10 @@ public: ...@@ -81,4 +81,10 @@ public:
val = std::stoi(str, nullptr); val = std::stoi(str, nullptr);
return true; return true;
} }
static bool ToNumber(const std::string& str, long long& val)
{
val = std::stoll(str, nullptr);
return true;
}
}; };
...@@ -144,7 +144,7 @@ static std::string DateToStr(int year, int month, int day, int hour, int minute, ...@@ -144,7 +144,7 @@ static std::string DateToStr(int year, int month, int day, int hour, int minute,
std::ostringstream ss; std::ostringstream ss;
if(!year_first) { if (!year_first) {
ss << std::setfill('0'); ss << std::setfill('0');
ss << std::setw(2) << day << "/"; ss << std::setw(2) << day << "/";
ss << std::setw(2) << month << "/"; ss << std::setw(2) << month << "/";
...@@ -152,7 +152,8 @@ static std::string DateToStr(int year, int month, int day, int hour, int minute, ...@@ -152,7 +152,8 @@ static std::string DateToStr(int year, int month, int day, int hour, int minute,
ss << std::setw(2) << d << ":"; ss << std::setw(2) << d << ":";
ss << std::setw(2) << m << ":";; ss << std::setw(2) << m << ":";;
ss << std::setw(2) << s; ss << std::setw(2) << s;
}else { }
else {
ss << std::setfill('0'); ss << std::setfill('0');
ss << std::setw(4) << year << "/"; ss << std::setw(4) << year << "/";
ss << std::setw(2) << month << "/"; ss << std::setw(2) << month << "/";
...@@ -503,3 +504,29 @@ inline TimeJD get_current_time() ...@@ -503,3 +504,29 @@ inline TimeJD get_current_time()
return now; return now;
} }
inline long long get_ts()
{
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count() / 1000;
}
inline long long get_ts(const TimeJD& date)
{
const TimeGD gd = date;
int jd;
double jf;
convertTimeGJ(
gd.Year,
gd.Month,
gd.Day,
gd.Hour,
gd.Min,
gd.Sec,
gd.Fraction,
jd,
jf);
return (jd + jf - 2440587.5) * 86400.0 * 1000;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment