Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Alexander Lapshin
common
Commits
74e024b9
Commit
74e024b9
authored
Jun 15, 2021
by
Alexander Lapshin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
+ get_ts, json loading data types, refactoring
parent
c309791e
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
279 additions
and
34 deletions
+279
-34
json_functions.h
json/json_functions.h
+205
-28
json_functions_bno.h
json/json_functions_bno.h
+36
-1
Converter.h
utils/Converter.h
+6
-0
TimeFunctions.h
utils/TimeFunctions.h
+32
-5
No files found.
json/json_functions.h
View file @
74e024b9
This diff is collapsed.
Click to expand it.
json/json_functions_bno.h
View file @
74e024b9
...
...
@@ -112,3 +112,38 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<TimeJ
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
;
}
utils/Converter.h
View file @
74e024b9
...
...
@@ -81,4 +81,10 @@ public:
val
=
std
::
stoi
(
str
,
nullptr
);
return
true
;
}
static
bool
ToNumber
(
const
std
::
string
&
str
,
long
long
&
val
)
{
val
=
std
::
stoll
(
str
,
nullptr
);
return
true
;
}
};
utils/TimeFunctions.h
View file @
74e024b9
...
...
@@ -144,7 +144,7 @@ static std::string DateToStr(int year, int month, int day, int hour, int minute,
std
::
ostringstream
ss
;
if
(
!
year_first
)
{
if
(
!
year_first
)
{
ss
<<
std
::
setfill
(
'0'
);
ss
<<
std
::
setw
(
2
)
<<
day
<<
"/"
;
ss
<<
std
::
setw
(
2
)
<<
month
<<
"/"
;
...
...
@@ -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
)
<<
m
<<
":"
;;
ss
<<
std
::
setw
(
2
)
<<
s
;
}
else
{
}
else
{
ss
<<
std
::
setfill
(
'0'
);
ss
<<
std
::
setw
(
4
)
<<
year
<<
"/"
;
ss
<<
std
::
setw
(
2
)
<<
month
<<
"/"
;
...
...
@@ -503,3 +504,29 @@ inline TimeJD get_current_time()
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
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment