kr0st / fpgui

GUI application for convenient browsing through fplog-generated log messages
MIT License
0 stars 0 forks source link

Need C++ function to convert timestamp exported to ChaiScript #1

Closed kr0st closed 6 years ago

kr0st commented 7 years ago

This is needed for sorting, ability to convert any timestamp with timezone into a single number.

kr0st commented 7 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;
}
kr0st commented 6 years ago

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.

kr0st commented 6 years ago

Fixed & tested.