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