-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #9
- Loading branch information
Showing
4 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Convert date and time strings to a friendlier format for .csv files | ||
|
||
#include "TimeAndDate.h" | ||
#include <ctime> | ||
|
||
using namespace std; | ||
|
||
const map<string,string> MONTHS = { | ||
{"Jan", "01"}, | ||
{"Feb", "02"}, | ||
{"Mar", "03"}, | ||
{"Apr", "04"}, | ||
{"May", "05"}, | ||
{"Jun", "06"}, | ||
{"Jul", "07"}, | ||
{"Aug", "08"}, | ||
{"Sep", "09"}, | ||
{"Oct", "10"}, | ||
{"Nov", "11"}, | ||
{"Dec", "12"} | ||
}; | ||
|
||
// Converts a date string to the format YYYY-MM-DD hh:mm:ss | ||
string TimeAndDate::FormatDate(string date_str) { | ||
string rtn_str = ""; | ||
|
||
rtn_str.append(date_str.substr(20, 4)); // Year | ||
rtn_str.append("-"); | ||
rtn_str.append(MONTHS.at(date_str.substr(4, 3))); // Month | ||
rtn_str.append("-"); | ||
string day = date_str.substr(8, 2); // Day | ||
if (day[0] == ' ') | ||
day[0] = '0'; | ||
rtn_str.append(day); | ||
rtn_str.append(date_str.substr(10, 9)); // Time | ||
|
||
return rtn_str; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef TIME_AND_DATE_H | ||
#define TIME_AND_DATE_H | ||
|
||
#include <string> | ||
#include <map> | ||
|
||
class TimeAndDate { | ||
public: | ||
static std::string FormatDate(std::string date_str); | ||
}; | ||
|
||
#endif /* TIME_AND_DATE_H */ |
This file contains 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