00001 /* 00002 * RawTime.hpp 00003 * 00004 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 00005 * 00006 * Oracle is a registered trademarks of Oracle Corporation and/or its 00007 * affiliates. 00008 * 00009 * This software is the confidential and proprietary information of Oracle 00010 * Corporation. You shall not disclose such confidential and proprietary 00011 * information and shall use it only in accordance with the terms of the 00012 * license agreement you entered into with Oracle. 00013 * 00014 * This notice may not be removed or altered. 00015 */ 00016 #ifndef COH_RAW_TIME_HPP 00017 #define COH_RAW_TIME_HPP 00018 00019 #include "coherence/lang.ns" 00020 00021 #include <ostream> 00022 #include <time.h> 00023 00024 COH_OPEN_NAMESPACE3(coherence,io,pof) 00025 00026 00027 /** 00028 * Raw immutable POF time value. 00029 * 00030 * @author jh 2008.04.08 00031 */ 00032 class COH_EXPORT RawTime 00033 : public cloneable_spec<RawTime> 00034 { 00035 friend class factory<RawTime>; 00036 00037 // ----- typedefs ------------------------------------------------------- 00038 00039 public: 00040 /** 00041 * The boxed native type. 00042 */ 00043 typedef struct tm BoxedType; 00044 00045 00046 // ----- constructors --------------------------------------------------- 00047 00048 protected: 00049 /** 00050 * Construct a raw POF time value. 00051 * 00052 * @param nHour the hour between 0 and 23 inclusive 00053 * @param nMinute the minute value between 0 and 59 inclusive 00054 * @param nSecond the second value between 0 and 59 inclusive (and 00055 * theoretically 60 for a leap-second) 00056 * @param nNano the nanosecond value between 0 and 999999999 00057 * inclusive 00058 * @param fUTC true if the time value is UTC or false if the time 00059 * value does not have an explicit time zone 00060 */ 00061 RawTime(int32_t nHour, int32_t nMinute, int32_t nSecond, 00062 int32_t nNano, bool fUTC); 00063 00064 /** 00065 * Construct a raw POF time value with a timezone. 00066 * 00067 * @param nHour the hour between 0 and 23 inclusive 00068 * @param nMinute the minute value between 0 and 59 inclusive 00069 * @param nSecond the second value between 0 and 59 inclusive 00070 * (and theoretically 60 for a leap-second) 00071 * @param nNano the nanosecond value between 0 and 999999999 00072 * inclusive 00073 * @param nHourOffset the timezone offset in hours from UTC, for 00074 * example 0 for BST, -5 for EST and 1 for CET 00075 * @param nMinuteOffset the timezone offset in minutes, for example 0 00076 * (in most cases) or 30 00077 */ 00078 RawTime(int32_t nHour, int32_t nMinute, int32_t nSecond, 00079 int32_t nNano, int32_t nHourOffset, int32_t nMinuteOffset); 00080 00081 /** 00082 * Construct a raw POF time value from a POSIX datetime struct. 00083 * 00084 * Note that the POSIX daylight savings flag is not preserved. 00085 * 00086 * @param timeinfo the POSIX time 00087 * @param fUTC true if the time value is UTC or false if the time 00088 * value does not have an explicit time zone 00089 */ 00090 RawTime(const struct tm& timeinfo, bool fUTC = false); 00091 00092 /** 00093 * Copy constructor. 00094 */ 00095 RawTime(const RawTime& that); 00096 00097 00098 // ----- Object interface ----------------------------------------------- 00099 00100 public: 00101 /** 00102 * {@inheritDoc} 00103 */ 00104 virtual bool equals(Object::View v) const; 00105 00106 /** 00107 * {@inheritDoc} 00108 */ 00109 virtual size32_t hashCode() const; 00110 00111 /** 00112 * {@inheritDoc} 00113 */ 00114 virtual bool isImmutable() const; 00115 00116 /** 00117 * {@inheritDoc} 00118 */ 00119 virtual void toStream(std::ostream &out) const; 00120 00121 00122 // ----- accessors ------------------------------------------------------ 00123 00124 public: 00125 /** 00126 * Determine the time's hour value. 00127 * 00128 * @return the hour between 0 and 23 inclusive 00129 */ 00130 virtual int32_t getHour() const; 00131 00132 /** 00133 * Determine the time's minute value. 00134 * 00135 * @return the minute value between 0 and 59 inclusive 00136 */ 00137 virtual int32_t getMinute() const; 00138 00139 /** 00140 * Determine the time's second value. 00141 * 00142 * @return the second value between 0 and 59 inclusive (and possibly 00143 * 60 for a leap-second) 00144 */ 00145 virtual int32_t getSecond() const; 00146 00147 /** 00148 * Determine the time's nanosecond value. 00149 * 00150 * @return the nanosecond value between 0 and 999999999 inclusive 00151 */ 00152 virtual int32_t getNano() const; 00153 00154 /** 00155 * Determine if the time value has an explicit timezone. A time value 00156 * without an explicit timezone is assumed to be in some conventional 00157 * local timezone, according to ISO8601. 00158 * 00159 * @return true iff the time has an explicit timezone 00160 */ 00161 virtual bool hasTimezone() const; 00162 00163 /** 00164 * Determine if the time value uses UTC. 00165 * 00166 * @return true if the time value is a UTC value 00167 */ 00168 virtual bool isUTC() const; 00169 00170 /** 00171 * Determine the timezone's hour offset value. 00172 * 00173 * @return the hour offset of the timezeone, or zero if there is no 00174 * explicit timezone or the time is UTC 00175 */ 00176 virtual int32_t getHourOffset() const; 00177 00178 /** 00179 * Determine the timezone's minute offset value. 00180 * 00181 * @return the minute offset of the timezeone, or zero if there is no 00182 * explicit timezone or the time is UTC 00183 */ 00184 virtual int32_t getMinuteOffset() const; 00185 00186 /** 00187 * Convert the RawTime to a POSIX datetime struct. 00188 * 00189 * Note that the nanosecond and timezone related information are not 00190 * preserved. 00191 * 00192 */ 00193 virtual operator struct tm() const; 00194 00195 00196 // ----- data members --------------------------------------------------- 00197 00198 protected: 00199 /** 00200 * The hour number. 00201 */ 00202 int32_t m_nHour; 00203 00204 /** 00205 * The minute number. 00206 */ 00207 int32_t m_nMinute; 00208 00209 /** 00210 * The second number. 00211 */ 00212 int32_t m_nSecond; 00213 00214 /** 00215 * The nanosecond number. 00216 */ 00217 int32_t m_nNano; 00218 00219 /** 00220 * The timezone indicator, one of the TZ_ enumerated constants. 00221 */ 00222 int32_t m_nTimeZoneType; 00223 00224 /** 00225 * The hour offset of the time's timezone. 00226 */ 00227 int32_t m_nHourOffset; 00228 00229 /** 00230 * The minute offset of the time's timezone. 00231 */ 00232 int32_t m_nMinuteOffset; 00233 }; 00234 00235 COH_CLOSE_NAMESPACE3 00236 00237 #endif // COH_RAW_TIME_HPP