1
1
#include " stonks_db.h"
2
2
3
- #include < chrono>
3
+ #include < absl/time/time.h>
4
+
4
5
#include < compare>
5
6
#include < limits>
6
7
#include < memory>
33
34
34
35
namespace stonks {
35
36
namespace {
36
- [[nodiscard]] auto GetStartTime (const Period *period)
37
- -> std::chrono::milliseconds {
37
+ [[nodiscard]] auto GetStartTime (const Period *period) -> absl::Time {
38
38
if ((period != nullptr ) && period->start_time .has_value ()) {
39
39
return *period->start_time ;
40
40
}
41
41
42
- return std::chrono::milliseconds::min ();
42
+ return absl::InfinitePast ();
43
43
}
44
44
45
- [[nodiscard]] auto GetEndTime (const Period *period)
46
- -> std::chrono::milliseconds {
45
+ [[nodiscard]] auto GetEndTime (const Period *period) -> absl::Time {
47
46
if ((period != nullptr ) && period->end_time .has_value ()) {
48
47
return *period->end_time ;
49
48
}
50
49
51
- return std::chrono::milliseconds::max ();
50
+ return absl::InfiniteFuture ();
52
51
}
53
52
54
53
[[nodiscard]] auto SymbolLess (const SymbolInfo &left, const SymbolInfo &right)
@@ -185,8 +184,8 @@ auto Db::SelectSymbolPriceTicks(const SymbolName *symbol, const Period *period,
185
184
? &prepared_statements_->SelectSymbolPriceTicks ()
186
185
: &prepared_statements_->SelectPriceTicks ();
187
186
auto values = [this , symbol, period, limit]() {
188
- auto values = sqldb::AsValues (GetStartTime (period). count ( ),
189
- GetEndTime (period). count ( ));
187
+ auto values = sqldb::AsValues (absl::ToUnixMillis ( GetStartTime (period)),
188
+ absl::ToUnixMillis ( GetEndTime (period)));
190
189
191
190
if (symbol != nullptr ) {
192
191
values.emplace_back (cache_.GetSymbolIdBySymbol (*symbol));
@@ -212,7 +211,7 @@ auto Db::SelectSymbolPriceTicks(const SymbolName *symbol, const Period *period,
212
211
for (auto i = 0 ; i < num_rows; ++i) {
213
212
price_ticks.emplace_back (SymbolPriceTick{
214
213
.symbol = cache_.GetSymbolBySymbolId (symbol_id[i].GetInt64 ()),
215
- .time = std::chrono::milliseconds{ time [i].GetInt64 ()} ,
214
+ .time = absl::FromUnixMillis ( time [i].GetInt64 ()) ,
216
215
.buy_price = buy_price[i].GetDouble (),
217
216
.sell_price = sell_price[i].GetDouble ()});
218
217
}
@@ -223,7 +222,7 @@ auto Db::SelectSymbolPriceTicks(const SymbolName *symbol, const Period *period,
223
222
void Db::InsertSymbolPriceTick (const SymbolPriceTick &symbol_price_tick) {
224
223
prepared_statements_->InsertPriceTick ().Execute (sqldb::AsValues (
225
224
cache_.GetSymbolIdBySymbol (symbol_price_tick.symbol ),
226
- symbol_price_tick.time . count ( ), symbol_price_tick.buy_price ,
225
+ absl::ToUnixMillis ( symbol_price_tick.time ), symbol_price_tick.buy_price ,
227
226
symbol_price_tick.sell_price ));
228
227
}
229
228
0 commit comments