00001 /* 00002 libwt - Vassilis Virvilis Toolkit - a widget library 00003 Copyright (C) 2006 Vassilis Virvilis <vasvir2@fastmail.fm> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the 00017 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, SA. 00019 */ 00020 00021 #ifndef WT_DATETIME_H 00022 #define WT_DATETIME_H 00023 00024 #include <string> 00025 00026 namespace Wt { 00027 00028 /// A time class to escape SDL's 2^32 ms epoch limitations 00029 class Time { 00030 public: 00031 Time(); 00032 Time(int h, int m, int s = 0, int ms = 0); 00033 bool isNull() const; 00034 bool isValid() const; 00035 int hour() const { 00036 return hour_; 00037 } 00038 int minute() const { 00039 return minute_; 00040 } 00041 int second() const { 00042 return second_; 00043 } 00044 int msec() const { 00045 return msec_; 00046 } 00047 00048 operator std::string() const; 00049 std::string toString() const; 00050 bool setHMS(int h, int m, int s, int ms = 0); 00051 Time addSecs(int nsecs) const; 00052 int secsTo(const Time& t) const; 00053 Time addMSecs(int ms) const; 00054 int msecsTo(const Time& t) const; 00055 bool operator==(const Time& t) const; 00056 bool operator!=(const Time& t) const; 00057 bool operator<(const Time& t) const; 00058 bool operator<=(const Time& t) const; 00059 bool operator>(const Time& t) const; 00060 bool operator>=(const Time& t) const; 00061 void start(); 00062 int restart(); 00063 int elapsed() const; 00064 00065 static Time currentTime(); 00066 static Time fromString(const std::string& s); 00067 static bool isValid(int h, int m, int s, int ms = 0); 00068 00069 private: 00070 int hour_; 00071 int minute_; 00072 int second_; 00073 int msec_; 00074 00075 // helpers 00076 int add_and_wrap(int& start, int duration, int range) const; 00077 }; 00078 00079 } 00080 00081 #endif // _TIME_H
This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.