Created
January 5, 2021 15:55
-
-
Save zeffii/6075ce96f7f1281a9f580ab0f833b10a to your computer and use it in GitHub Desktop.
cpp time solutions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I spent a large portion of today fighting the C++ timelord. it now yields useful results