00001 /* 00002 * 00003 * Copyright (C) 2002-2005, OFFIS 00004 * 00005 * This software and supporting documentation were developed by 00006 * 00007 * Kuratorium OFFIS e.V. 00008 * Healthcare Information and Communication Systems 00009 * Escherweg 2 00010 * D-26121 Oldenburg, Germany 00011 * 00012 * THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND OFFIS MAKES NO WARRANTY 00013 * REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY OR 00014 * FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES OR 00015 * ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND 00016 * PERFORMANCE OF THE SOFTWARE IS WITH THE USER. 00017 * 00018 * Module: ofstd 00019 * 00020 * Author: Joerg Riesmeier 00021 * 00022 * Purpose: Class for time functions 00023 * 00024 * Last Update: $Author: meichel $ 00025 * Update Date: $Date: 2005/12/08 16:06:09 $ 00026 * CVS/RCS Revision: $Revision: 1.8 $ 00027 * Status: $State: Exp $ 00028 * 00029 * CVS/RCS Log at end of file 00030 * 00031 */ 00032 00033 00034 #ifndef OFTIME_H 00035 #define OFTIME_H 00036 00037 #include "dcmtk/config/osconfig.h" 00038 00039 BEGIN_EXTERN_C 00040 #ifdef HAVE_SYS_TYPES_H 00041 # include <sys/types.h> /* for struct time_t */ 00042 #endif 00043 END_EXTERN_C 00044 00045 #include "dcmtk/ofstd/ofstring.h" /* for class OFString */ 00046 00047 00048 /*---------------------* 00049 * class declaration * 00050 *---------------------*/ 00051 00054 class OFTime 00055 { 00056 // allow class OFDateTime to access protected class members 00057 friend class OFDateTime; 00058 00059 00060 public: 00061 00065 OFTime(); 00066 00070 OFTime(const OFTime &timeVal); 00071 00078 OFTime(const unsigned int hour, 00079 const unsigned int minute, 00080 const double second, 00081 const double timeZone = 0); 00082 00085 virtual ~OFTime(); 00086 00091 virtual OFTime &operator=(const OFTime &timeVal); 00092 00099 virtual OFBool operator==(const OFTime &timeVal) const; 00100 00107 virtual OFBool operator!=(const OFTime &timeVal) const; 00108 00115 virtual OFBool operator<(const OFTime &timeVal) const; 00116 00124 virtual OFBool operator<=(const OFTime &timeVal) const; 00125 00133 virtual OFBool operator>=(const OFTime &timeVal) const; 00134 00141 virtual OFBool operator>(const OFTime &timeVal) const; 00142 00146 virtual void clear(); 00147 00153 virtual OFBool isValid() const; 00154 00163 OFBool setTime(const unsigned int hour, 00164 const unsigned int minute, 00165 const double second, 00166 const double timeZone = 0); 00167 00173 OFBool setHour(const unsigned int hour); 00174 00180 OFBool setMinute(const unsigned int minute); 00181 00187 OFBool setSecond(const double second); 00188 00197 OFBool setTimeZone(const double timeZone); 00198 00207 OFBool setTimeZone(const signed int hour, 00208 const unsigned int minute); 00209 00217 OFBool setTimeInSeconds(const double seconds, 00218 const double timeZone = 0, 00219 const OFBool normalize = OFTrue); 00220 00228 OFBool setTimeInHours(const double hours, 00229 const double timeZone = 0, 00230 const OFBool normalize = OFTrue); 00231 00237 OFBool setCurrentTime(); 00238 00247 OFBool setISOFormattedTime(const OFString &formattedTime); 00248 00252 unsigned int getHour() const; 00253 00257 unsigned int getMinute() const; 00258 00262 double getSecond() const; 00263 00267 unsigned int getIntSecond() const; 00268 00272 unsigned int getMilliSecond() const; 00273 00277 unsigned int getMicroSecond() const; 00278 00285 double getTimeZone() const; 00286 00293 double getTimeInSeconds(const OFBool useTimeZone = OFFalse, 00294 const OFBool normalize = OFTrue) const; 00295 00302 double getTimeInHours(const OFBool useTimeZone = OFFalse, 00303 const OFBool normalize = OFTrue) const; 00304 00310 OFTime getCoordinatedUniversalTime() const; 00311 00316 OFTime getLocalTime() const; 00317 00332 OFBool getISOFormattedTime(OFString &formattedTime, 00333 const OFBool showSeconds = OFTrue, 00334 const OFBool showFraction = OFFalse, 00335 const OFBool showTimeZone = OFFalse, 00336 const OFBool showDelimiter = OFTrue) const; 00337 00338 /* --- static helper functions --- */ 00339 00343 static OFTime getCurrentTime(); 00344 00350 static double getLocalTimeZone(); 00351 00352 00353 protected: 00354 00361 OFBool setCurrentTime(const time_t &tt); 00362 00363 /* --- static helper functions --- */ 00364 00374 static OFBool isTimeValid(const unsigned int hour, 00375 const unsigned int minute, 00376 const double second, 00377 const double timeZone); 00378 00388 static double getTimeInSeconds(const unsigned int hour, 00389 const unsigned int minute, 00390 const double second, 00391 const double timeZone = 0, 00392 const OFBool normalize = OFTrue); 00393 00403 static double getTimeInHours(const unsigned int hour, 00404 const unsigned int minute, 00405 const double second, 00406 const double timeZone = 0, 00407 const OFBool normalize = OFTrue); 00408 00409 00410 private: 00411 00413 unsigned int Hour; 00414 00416 unsigned int Minute; 00417 00419 double Second; 00420 00422 double TimeZone; 00423 }; 00424 00425 00432 ostream& operator<<(ostream& stream, const OFTime &timeVal); 00433 00434 00435 #endif 00436 00437 00438 /* 00439 * 00440 * CVS/RCS Log: 00441 * $Log: oftime.h,v $ 00442 * Revision 1.8 2005/12/08 16:06:09 meichel 00443 * Changed include path schema for all DCMTK header files 00444 * 00445 * Revision 1.7 2004/01/16 10:30:39 joergr 00446 * Added setISOFormattedXXX() methods for Date, Time and DateTime. 00447 * 00448 * Revision 1.6 2003/12/17 15:18:48 joergr 00449 * Fixed bug/inconsistency in comparison operators of class OFTime. Now the 00450 * "time overflow" is handled correctly. 00451 * 00452 * Revision 1.5 2003/09/15 12:12:56 joergr 00453 * Fixed incorrect/improper comments of the comparision operators. Enhanced 00454 * comment of the default constructor. Made comparison operators const. 00455 * 00456 * Revision 1.4 2002/05/24 09:43:05 joergr 00457 * Renamed some parameters/variables to avoid ambiguities. 00458 * 00459 * Revision 1.3 2002/04/19 10:42:51 joergr 00460 * Added new helper routines to get the milli and micro seconds part as well as 00461 * the integral value of seconds. 00462 * 00463 * Revision 1.2 2002/04/15 09:38:59 joergr 00464 * Added "include <sys/types.h>" for struct time_t (required for MSVC). 00465 * 00466 * Revision 1.1 2002/04/11 12:12:24 joergr 00467 * Introduced new standard classes providing date and time functions. 00468 * 00469 * 00470 */