Advertisement
serikov

yandex class time

Jun 23rd, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. class Time {
  2.   public:
  3.  
  4.     Time();
  5.  
  6.     bool Parse(string time) {
  7.            hours = 0;
  8.            minutes = 0;
  9.                boost::regex xRegEx1("^([0-2][0-9])([0-5][0-9])(\\s[AP]M)");
  10.                boost::smatch xResults;
  11.                if (!boost::regex_match(time, xResults, xRegEx1)) {
  12.             hours = strtol(xResults[1].str().c_str(), NULL, 10);
  13.             minutes = strtol(xResults[2].str().c_str(), NULL, 10);
  14.             if (strcmp(xResults[3].str().c_str(), "PM")==0)  hours = hours + 12;
  15.             return true;
  16.                } else return false;
  17.     }
  18.  
  19.     int GetHours () {
  20.         return hours;
  21.     }  
  22.  
  23.     int GetMinutes() {
  24.         return hours;
  25.     }  
  26.    
  27.     private:
  28.      int hours;
  29.      int minutes;
  30. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement