示例#1
0
int main(int argc, const char * argv[]) {
    // insert code here...
    vector<Time> times;
    Time t1;
    Time t2;
    Time t3(12,4,1);
    Time t4(24,47,47);
    Time t5(11,7,1);
    t3.printAmPm();
    t4.printAmPm();
    t5.printAmPm();
//    for(int i=0; i<24; i++){
//        times.push_back(Time(i,i,i));
//    }
    for(int i=0; i<24; i++){
        times.push_back(Time(i,i,i+1));
    }
    sort(times.begin(), times.end(), isEarlierThan);
    for(int i=0; i< times.size(); i++){
        times[i].printAmPm();
    }
    cout << t1.getHour() << t2.getHour() <<endl;
    cout << "t3 is earlier than t4: " << isEarlierThan(t3,t4) << endl;
}
示例#2
0
bool DateTime::isLaterThan(DateTime other) {
    if(isEarlierThan(other) || equals(other))
        return false;
    else  
        return true;
}
示例#3
0
        Time minus(Time& t)
        {
            Time rtn;
            int temp;
            if(isEarlierThan(t)) 
            {
                std::cout << "The first is smaller than the latter." << std::endl;
                goto e;
            }
            else 
            {
                rtn.day = day-t.day;
                if(hour < t.hour)
                {
                    if(rtn.day == 0)
                    {
                        std::cout << "The first is smaller than the latter." << std::endl;
                        goto e;
                    }
                    else
                    {
                        rtn.hour = hour + 24 - t.hour;
                        rtn.day --;
                    }
                }
                else 
                {
                    rtn.hour = hour - t.hour;
                    if(min < t.min)
                    {
                        if(rtn.hour == 0)
                        {
                            std::cout << "The first is smaller than the latter." << std::endl;
                            goto e;
                        }
                        else
                        {
                            rtn.min = min + 60 - t.min;
                            rtn.min --;
                        }
                    }
                    else
                    {
                        rtn.min = min - t.min;
                        if(sec < t.sec)
                        {
                            if(rtn.hour == 0)
                            {
                                std::cout << "The first is smaller than the latter." << std::endl;
                                goto e;
                            }
                            else
                            {
                                rtn.sec = sec + 60 - t.sec;
                                rtn.sec --;
                            }
                        }
                        else rtn.sec = sec - t.sec;
                    }
                }
            }
e: ;
        }