Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Timer.h"
- #include "memoryMN.h"
- std::map<std::string, int> study_log;
- std::map<std::string, int>::iterator study_iter;
- Timer::Timer()
- {
- }
- Timer::~Timer()
- {
- }
- //Function has an side effect of
- timeObj *Timer::timeCounting() { //timeObj- std::chrono::time_point<std::chrono::system_clock>
- timeObj *now = new timeObj(std::chrono::system_clock::now());
- return now;
- }
- //If true it would print the current date, else not.
- timeObj *Timer::timeCounting(bool print_or_not) {
- timeObj *now = new timeObj(std::chrono::system_clock::now());
- if (print_or_not) {
- printDate(now);
- }
- return now;
- }
- timeObj *Timer::compareDiff(timeObj *start, timeObj *end, bool print_or_not) {
- auto int_min = std::chrono::duration_cast<std::chrono::minutes>(*end - *start); //The diffrenece between start and end.
- timeObj *now = new timeObj(int_min);
- if (print_or_not) {
- std::stringstream ss;
- ss << int_min.count() << std::flush;
- std::cout << "You have studied for " << ss.str() << " minutes." << std::endl;
- }
- return now;
- }
- //Puts it all toghether.
- void Timer::countIt() {
- bool first_time = true;
- bool keep_sess = true;
- bool make_dec = false;
- while (keep_sess) {
- operateTimeCount(first_time);
- std::string ans;
- while (!make_dec) {
- std::cout << "Would you like to continue? if so press \"yes\", else press \"no\"" << std::endl;
- std::cin >> ans;
- if (ans == "yes") {
- keep_sess = true;
- make_dec = true;
- }
- else if (ans == "no") {
- keep_sess = false;
- make_dec = true;
- }
- }
- make_dec = false;
- first_time = false;
- }
- }
- void Timer::operateTimeCount(bool first_time) {
- if (!first_time) {
- std::cout << "-----------------------------------------\n" << std::endl;
- }
- std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- std::cout << "Starting time is" << std::flush;
- timeObj *start = timeCounting(true);
- std::cout << "Press enter when you wish to take a break" << std::endl;
- std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- timeObj *end = timeCounting(true);
- timeObj *diff = compareDiff(start, end, true);
- auto int_min = std::chrono::duration_cast<std::chrono::minutes>(*end - *start);
- int how_long = int_min.count();
- std::string date_sess_str(retDateOfSession(start, end));
- std::cout << date_sess_str << std::endl;
- study_log.insert(std::make_pair(std::string(date_sess_str), how_long));
- //Delete all pointed objects from other functions...
- safeDelete(start);
- safeDelete(end);
- safeDelete(diff);
- }
- void Timer::printDate(const timeObj *date) {
- auto in_time_t = std::chrono::system_clock::to_time_t(*date);
- std::stringstream ss;
- ss << std::put_time(std::localtime(&in_time_t), "%Y/%m/%d %X");
- std::cout << ss.str() << std::endl;
- }
- std::string Timer::retDateOfSession(const timeObj *date1, const timeObj *date2) {
- auto in_time_t1 = std::chrono::system_clock::to_time_t(*date1);
- auto in_time_t2 = std::chrono::system_clock::to_time_t(*date2);
- std::stringstream ss;
- ss << std::put_time(std::localtime(&in_time_t1), "%Y/%m/%d %X") << " - "
- << std::put_time(std::localtime(&in_time_t1), "%Y/%m/%d %X") << std::endl;
- return ss.str();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement