Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created January 5, 2021 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/6075ce96f7f1281a9f580ab0f833b10a to your computer and use it in GitHub Desktop.
Save zeffii/6075ce96f7f1281a9f580ab0f833b10a to your computer and use it in GitHub Desktop.
cpp time solutions
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <string>
#include <sstream>
#include <iostream>
#include <time.h>
#include <ctime>
#include <vector>
#include <fstream>
#include <iomanip>
std::vector<std::string> lines;
int epoch_from_string(std::string time_str)
{
int epoch = 0;
std::tm t = {};
std::istringstream ss(time_str);
if (ss >> std::get_time(&t, "%d/%m/%Y %H:%M")) {
std::put_time(&t, "%c");
std::stringstream buffer;
buffer << std::mktime(&t);
epoch = stoi( buffer.str() );
} else {
std::cout << "Parse failed" << std::endl;
}
return epoch;
}
void load_csv_file(){
std::string filepath = "C://2020/recent_bloodsugar.csv";
std::ifstream file (filepath);
std::string header_names;
getline(file, header_names);
std::string s;
while (getline(file, s))
lines.push_back(s);
file.close();
};
int main(int argc, char* args[])
{
load_csv_file();
for (auto s: lines){
std::string strrepr = s.substr(0, 16); //"24/12/2020 17:30";
int epoch = epoch_from_string(strrepr);
std::cout << epoch << std::endl;
}
while(true){}
return 0;
}
@zeffii
Copy link
Author

zeffii commented Jan 5, 2021

I spent a large portion of today fighting the C++ timelord. it now yields useful results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment