OWBI1_DateTime.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
00029 *******************************************************************************/
00030 
00036 #ifndef OWBI1_DATETIME_HPP_INCLUDE_GUARD_
00037 #define OWBI1_DATETIME_HPP_INCLUDE_GUARD_
00038 #include "OWBI1_config.h"
00039 #include "OWBI1_Exception.hpp"
00040 #include "OWBI1_Types.hpp"
00041 #include "OWBI1_CommonFwd.hpp"
00042 
00043 extern "C"
00044 {
00045 #include <time.h>
00046 }
00047 
00048 namespace OWBI1
00049 {
00050 
00051 OWBI1_DECLARE_APIEXCEPTION(DateTime, OWBI1_COMMON_API)
00052 
00053 
00077 class OWBI1_COMMON_API DateTime
00078 {
00079 public:
00087    enum ETimeOffset
00088    {
00089       E_LOCAL_TIME,
00090       E_UTC_TIME
00091    };
00092 
00097    DateTime();
00175    explicit DateTime(const String& str);
00185    explicit DateTime(time_t t, UInt32 microseconds=0);
00198    DateTime(int year, int month, int day, int hour=0, int minute=0,
00199       int second=0, UInt32 microsecond=0, ETimeOffset timeOffset = E_LOCAL_TIME);
00200 
00201    explicit DateTime(const detail::DateTimeRepRef& rep);
00205    ~DateTime();
00212    int getHour(ETimeOffset timeOffset = E_LOCAL_TIME) const;
00219    int getMinute(ETimeOffset timeOffset = E_LOCAL_TIME) const;
00227    int getSecond(ETimeOffset timeOffset = E_LOCAL_TIME) const;
00235    UInt32 getMicrosecond() const;
00242    int getDay(ETimeOffset timeOffset = E_LOCAL_TIME) const;
00248    int getDow(ETimeOffset timeOffset = E_LOCAL_TIME) const;
00253    int getMonth(ETimeOffset timeOffset = E_LOCAL_TIME) const;
00258    int getYear(ETimeOffset timeOffset = E_LOCAL_TIME) const;
00262    time_t get() const;
00269    void setHour(int hour, ETimeOffset timeOffset = E_LOCAL_TIME);
00276    void setMinute(int minute, ETimeOffset timeOffset = E_LOCAL_TIME);
00283    void setSecond(int second, ETimeOffset timeOffset = E_LOCAL_TIME);
00290    void setMicrosecond(UInt32 microsecond);
00299    void setTime(int hour, int minute, int second, ETimeOffset timeOffset = E_LOCAL_TIME);
00306    void setDay(int day, ETimeOffset timeOffset = E_LOCAL_TIME);
00313    void setMonth(int month, ETimeOffset timeOffset = E_LOCAL_TIME);
00320    void setYear(int year, ETimeOffset timeOffset = E_LOCAL_TIME);
00328    void set(time_t t, UInt32 microseconds=0);
00341    void set(int year, int month, int day, int hour, int minute, int second, UInt32 microseconds, ETimeOffset timeOffset = E_LOCAL_TIME);
00345    void setToCurrent();
00351    void addDays(int days);
00357    void addWeeks(int weeks)
00358    {
00359       addDays(weeks * 7);
00360    }
00366    void addMonths(int months);
00372    void addYears(int years);
00378    void addSeconds(long seconds);
00383    void addMinutes(long minutes);
00388    void addHours(long hours);
00394    bool operator< ( const DateTime& tm ) const;
00400    bool operator> ( const DateTime& tm ) const
00401    {
00402       return tm < *this;
00403    }
00409    bool operator== ( const DateTime& tm ) const;
00415    bool operator!= ( const DateTime& tm ) const
00416    {
00417       return !(*this == tm);
00418    }
00425    bool operator<= ( const DateTime& tm ) const
00426    {
00427       return !(tm < *this);
00428    }
00435    bool operator>= ( const DateTime& tm ) const
00436    {
00437       return !(*this < tm);
00438    }
00444    DateTime& operator+= (long seconds)
00445    {
00446       addSeconds(seconds);
00447       return *this;
00448    }
00454    DateTime& operator-= (long seconds)
00455    {
00456       addSeconds(-seconds);
00457       return *this;
00458    }
00459 
00465    String toString(ETimeOffset timeOffset = E_LOCAL_TIME) const;
00466 
00476    String toString(
00477       char const * format, ETimeOffset timeOffset = E_LOCAL_TIME) const;
00478 
00484    static char const DEFAULT_FORMAT[];
00485 
00491    static Int16 getGMTOffsetMinutesNow()
00492    {
00493       time_t t = time(0);
00494       struct tm tt;
00495       return DateTime::localTimeAndOffset(t, tt);
00496    }
00497 
00503    Int16 toLocal(struct tm & tt) const;
00504 
00508    static DateTime getCurrent();
00509 
00510    detail::DateTimeRepRef getRep() const;
00511 
00512 private:
00513    detail::DateTimeRepRef m_rep;
00514 
00515    tm getTm(ETimeOffset timeOffset) const;
00516    void setTime(tm& tmarg, ETimeOffset timeOffset);
00517    static Int16 localTimeAndOffset(time_t t, struct tm & tt);
00518 };
00519 
00520 } // end namespace OWBI1
00521 
00522 #endif

Generated on Thu Feb 9 08:48:27 2006 for openwbem by  doxygen 1.4.6