ofstd/include/dcmtk/ofstd/oftime.h

00001 /*
00002  *
00003  *  Copyright (C) 2002-2010, OFFIS e.V.
00004  *  All rights reserved.  See COPYRIGHT file for details.
00005  *
00006  *  This software and supporting documentation were developed by
00007  *
00008  *    OFFIS e.V.
00009  *    R&D Division Health
00010  *    Escherweg 2
00011  *    D-26121 Oldenburg, Germany
00012  *
00013  *
00014  *  Module:  ofstd
00015  *
00016  *  Author:  Joerg Riesmeier
00017  *
00018  *  Purpose: Class for time functions
00019  *
00020  *  Last Update:      $Author: joergr $
00021  *  Update Date:      $Date: 2010-10-14 13:15:50 $
00022  *  CVS/RCS Revision: $Revision: 1.11 $
00023  *  Status:           $State: Exp $
00024  *
00025  *  CVS/RCS Log at end of file
00026  *
00027  */
00028 
00029 
00030 #ifndef OFTIME_H
00031 #define OFTIME_H
00032 
00033 #include "dcmtk/config/osconfig.h"
00034 
00035 #define INCLUDE_CTIME
00036 #include "dcmtk/ofstd/ofstdinc.h"
00037 
00038 BEGIN_EXTERN_C
00039 #ifdef HAVE_SYS_TYPES_H
00040 # include <sys/types.h>    /* for struct time_t */
00041 #endif
00042 END_EXTERN_C
00043 
00044 #include "dcmtk/ofstd/ofstring.h"      /* for class OFString */
00045 
00046 
00047 /*---------------------*
00048  *  class declaration  *
00049  *---------------------*/
00050 
00053 class OFTime
00054 {
00055     // allow class OFDateTime to access protected class members
00056     friend class OFDateTime;
00057 
00058 
00059  public:
00060 
00064     OFTime();
00065 
00069     OFTime(const OFTime &timeVal);
00070 
00077     OFTime(const unsigned int hour,
00078            const unsigned int minute,
00079            const double second,
00080            const double timeZone = 0);
00081 
00084     virtual ~OFTime();
00085 
00090     virtual OFTime &operator=(const OFTime &timeVal);
00091 
00098     virtual OFBool operator==(const OFTime &timeVal) const;
00099 
00106     virtual OFBool operator!=(const OFTime &timeVal) const;
00107 
00114     virtual OFBool operator<(const OFTime &timeVal) const;
00115 
00123     virtual OFBool operator<=(const OFTime &timeVal) const;
00124 
00132     virtual OFBool operator>=(const OFTime &timeVal) const;
00133 
00140     virtual OFBool operator>(const OFTime &timeVal) const;
00141 
00145     virtual void clear();
00146 
00152     virtual OFBool isValid() const;
00153 
00162     OFBool setTime(const unsigned int hour,
00163                    const unsigned int minute,
00164                    const double second,
00165                    const double timeZone = 0);
00166 
00172     OFBool setHour(const unsigned int hour);
00173 
00179     OFBool setMinute(const unsigned int minute);
00180 
00186     OFBool setSecond(const double second);
00187 
00196     OFBool setTimeZone(const double timeZone);
00197 
00206     OFBool setTimeZone(const signed int hour,
00207                        const unsigned int minute);
00208 
00216     OFBool setTimeInSeconds(const double seconds,
00217                             const double timeZone = 0,
00218                             const OFBool normalize = OFTrue);
00219 
00227     OFBool setTimeInHours(const double hours,
00228                           const double timeZone = 0,
00229                           const OFBool normalize = OFTrue);
00230 
00236     OFBool setCurrentTime();
00237 
00246     OFBool setISOFormattedTime(const OFString &formattedTime);
00247 
00251     unsigned int getHour() const;
00252 
00256     unsigned int getMinute() const;
00257 
00261     double getSecond() const;
00262 
00266     unsigned int getIntSecond() const;
00267 
00271     unsigned int getMilliSecond() const;
00272 
00276     unsigned int getMicroSecond() const;
00277 
00284     double getTimeZone() const;
00285 
00292     double getTimeInSeconds(const OFBool useTimeZone = OFFalse,
00293                             const OFBool normalize = OFTrue) const;
00294 
00301     double getTimeInHours(const OFBool useTimeZone = OFFalse,
00302                           const OFBool normalize = OFTrue) const;
00303 
00309     OFTime getCoordinatedUniversalTime() const;
00310 
00315     OFTime getLocalTime() const;
00316 
00331     OFBool getISOFormattedTime(OFString &formattedTime,
00332                                const OFBool showSeconds = OFTrue,
00333                                const OFBool showFraction = OFFalse,
00334                                const OFBool showTimeZone = OFFalse,
00335                                const OFBool showDelimiter = OFTrue) const;
00336 
00337     /* --- static helper functions --- */
00338 
00342     static OFTime getCurrentTime();
00343 
00349     static double getLocalTimeZone();
00350 
00351 
00352  protected:
00353 
00360     OFBool setCurrentTime(const time_t &tt);
00361 
00362     /* --- static helper functions --- */
00363 
00373     static OFBool isTimeValid(const unsigned int hour,
00374                               const unsigned int minute,
00375                               const double second,
00376                               const double timeZone);
00377 
00387     static double getTimeInSeconds(const unsigned int hour,
00388                                    const unsigned int minute,
00389                                    const double second,
00390                                    const double timeZone = 0,
00391                                    const OFBool normalize = OFTrue);
00392 
00402     static double getTimeInHours(const unsigned int hour,
00403                                  const unsigned int minute,
00404                                  const double second,
00405                                  const double timeZone = 0,
00406                                  const OFBool normalize = OFTrue);
00407 
00408 
00409  private:
00410 
00412     unsigned int Hour;
00413 
00415     unsigned int Minute;
00416 
00418     double Second;
00419 
00421     double TimeZone;
00422 };
00423 
00424 
00431 STD_NAMESPACE ostream& operator<<(STD_NAMESPACE ostream& stream, const OFTime &timeVal);
00432 
00433 
00434 #endif
00435 
00436 
00437 /*
00438  *
00439  * CVS/RCS Log:
00440  * $Log: oftime.h,v $
00441  * Revision 1.11  2010-10-14 13:15:50  joergr
00442  * Updated copyright header. Added reference to COPYRIGHT file.
00443  *
00444  * Revision 1.10  2009-08-19 11:55:45  meichel
00445  * Added additional includes needed for Sun Studio 11 on Solaris.
00446  *
00447  * Revision 1.9  2006-08-14 16:42:26  meichel
00448  * Updated all code in module ofstd to correctly compile if the standard
00449  *   namespace has not included into the global one with a "using" directive.
00450  *
00451  * Revision 1.8  2005/12/08 16:06:09  meichel
00452  * Changed include path schema for all DCMTK header files
00453  *
00454  * Revision 1.7  2004/01/16 10:30:39  joergr
00455  * Added setISOFormattedXXX() methods for Date, Time and DateTime.
00456  *
00457  * Revision 1.6  2003/12/17 15:18:48  joergr
00458  * Fixed bug/inconsistency in comparison operators of class OFTime. Now the
00459  * "time overflow" is handled correctly.
00460  *
00461  * Revision 1.5  2003/09/15 12:12:56  joergr
00462  * Fixed incorrect/improper comments of the comparision operators. Enhanced
00463  * comment of the default constructor. Made comparison operators const.
00464  *
00465  * Revision 1.4  2002/05/24 09:43:05  joergr
00466  * Renamed some parameters/variables to avoid ambiguities.
00467  *
00468  * Revision 1.3  2002/04/19 10:42:51  joergr
00469  * Added new helper routines to get the milli and micro seconds part as well as
00470  * the integral value of seconds.
00471  *
00472  * Revision 1.2  2002/04/15 09:38:59  joergr
00473  * Added "include <sys/types.h>" for struct time_t (required for MSVC).
00474  *
00475  * Revision 1.1  2002/04/11 12:12:24  joergr
00476  * Introduced new standard classes providing date and time functions.
00477  *
00478  *
00479  */


Generated on 6 Jan 2011 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.5.1