Closed kr0st closed 6 years ago
Experimenting for now here:
https://wandbox.org/permlink/n6NEh9nFCWLVgm1Q
#include "date.h"
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <locale>
#include <ostream>
#include <stdexcept>
#include <string>
int
main()
{
auto tp(std::chrono::system_clock::now());
std::string res;
std::string datetime(date::format("%FT%T", tp));
std::string tz_only(date::format("%z", tp));
for (auto it(datetime.begin()); it != datetime.end(); it++)
{
if ((*it == '.') || (*it == ','))
{
it += 4;
res.append(datetime.begin(), it);
res += tz_only;
std::cout << res;
}
}
std::chrono::minutes offset;
std::chrono::seconds tp2;
std::stringstream ss(res);
date::from_stream(ss, "%FT%T%z", tp2, (std::string*)(0), &offset);
return 0;
}
There is such function now generic_utils::date_time::iso_timestamp_to_ms(...) This function returns number of ms since 1st of Jan, 1970 and takes into account the time zone in the timestamp it converts. What's left is to expose this function to the ChaiScript.
Fixed & tested.
This is needed for sorting, ability to convert any timestamp with timezone into a single number.