PixelLightAPI  .
Time.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: Time.h                                         *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLCORE_TIME_H__
00024 #define __PLCORE_TIME_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/String/String.h"
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Namespace                                             ]
00036 //[-------------------------------------------------------]
00037 namespace PLCore {
00038 
00039 
00040 //[-------------------------------------------------------]
00041 //[ Classes                                               ]
00042 //[-------------------------------------------------------]
00043 /**
00044 *  @brief
00045 *    Time and date class
00046 *
00047 *  @note
00048 *    - If the year is between [1970..January 19, 2038] it's Unix/POSIX (32 bit) compatible
00049 *    - If the year is between [1980..January 1, 2108] it's DOS compatible
00050 */
00051 class Time {
00052 
00053 
00054     //[-------------------------------------------------------]
00055     //[ Public definitions                                    ]
00056     //[-------------------------------------------------------]
00057     public:
00058         /**
00059         *  @brief
00060         *    Month of year enumeration
00061         */
00062         enum EMonth {
00063             January = 1,    /**< January */
00064             February,       /**< February */
00065             March,          /**< March */
00066             April,          /**< April */
00067             May,            /**< May */
00068             June,           /**< June */
00069             July,           /**< July */
00070             August,         /**< August */
00071             September,      /**< September */
00072             October,        /**< October */
00073             November,       /**< November */
00074             December        /**< December */
00075         };
00076 
00077         /**
00078         *  @brief
00079         *    Day of week enumeration
00080         */
00081         enum EDay {
00082             Sunday = 0, /**< Sunday */
00083             Monday,     /**< Monday */
00084             Tuesday,    /**< Tuesday */
00085             Wednesday,  /**< Wednesday */
00086             Thursday,   /**< Thursday */
00087             Friday,     /**< Friday */
00088             Saturday    /**< Saturday */
00089         };
00090 
00091 
00092     //[-------------------------------------------------------]
00093     //[ Public static data                                    ]
00094     //[-------------------------------------------------------]
00095     public:
00096         static PLCORE_API const Time   Null;                    /**< Year=0 Month=January Day=1 DayOfWeek=Sunday Hour=0 Minute=0 Second=0 Millisecond=0 */
00097         static PLCORE_API const Time   UnixEpochStart;      /**< Year=1970 Month=January Day=1 DayOfWeek=Thursday Hour=0 Minute=0 Second=0 Millisecond=0 */
00098         static PLCORE_API const Time   DOSEpochStart;       /**< Year=1980 Month=January Day=1 DayOfWeek=Tuesday Hour=0 Minute=0 Second=0 Millisecond=0 */
00099         static PLCORE_API const String ShortMonthName[12];  /**< Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec */
00100         static PLCORE_API const String ShortDayName[7];     /**< Sun, Mon, Tue, Wed, Thu, Fri, Sat */
00101 
00102 
00103     //[-------------------------------------------------------]
00104     //[ Public static functions                               ]
00105     //[-------------------------------------------------------]
00106     public:
00107         /**
00108         *  @brief
00109         *    Returns whether or not the given year is a leap year
00110         *
00111         *  @param[in] nYear
00112         *    Year to check
00113         *
00114         *  @return
00115         *    'true' if the the given year is a leap year, else 'false'
00116         */
00117         static PLCORE_API bool IsLeapYear(uint32 nYear);
00118 
00119         /**
00120         *  @brief
00121         *    Returns the number of days in a month
00122         *
00123         *  @param[in] nMonth
00124         *    Month to check
00125         *  @param[in] nYear
00126         *    Year to check (0 == ignore, and assume no leap year)
00127         *
00128         *  @return
00129         *    Number of days in the given month
00130         */
00131         static PLCORE_API uint8 GetDaysPerMonth(EMonth nMonth, uint32 nYear = 0);
00132 
00133         /**
00134         *  @brief
00135         *    Calculates the day of a week
00136         *
00137         *  @param[in] nDayOfMonth
00138         *    Day of month
00139         *  @param[in] nMonth
00140         *    Month
00141         *  @param[in] nYear
00142         *    Year
00143         *
00144         *  @return
00145         *    The day of a week
00146         */
00147         static PLCORE_API EDay CalculateDayOfWeek(uint8 nDayOfMonth, EMonth nMonth, uint16 nYear);
00148 
00149 
00150     //[-------------------------------------------------------]
00151     //[ Public functions                                      ]
00152     //[-------------------------------------------------------]
00153     public:
00154         /**
00155         *  @brief
00156         *    Constructor
00157         */
00158         PLCORE_API Time();
00159 
00160         /**
00161         *  @brief
00162         *    Constructor
00163         *
00164         *  @param[in] nYear
00165         *    Year
00166         *  @param[in] nMonth
00167         *    Month [January..December]
00168         *  @param[in] nDayOfMonth
00169         *    Day of the month [1..31]
00170         *  @param[in] nDayOfWeek
00171         *    Day of the week [Sunday..Saturday]
00172         *  @param[in] nHour
00173         *    Hour [0..23]
00174         *  @param[in] nMinute
00175         *    Minute [0..59]
00176         *  @param[in] nSecond
00177         *    Second [0..59]
00178         *  @param[in] nMillisecond
00179         *    Millisecond [0..999]
00180         */
00181         PLCORE_API Time(uint16 nYear, EMonth nMonth, uint8 nDayOfMonth, EDay nDayOfWeek, uint8 nHour, uint8 nMinute, uint8 nSecond, uint16 nMillisecond);
00182 
00183         /**
00184         *  @brief
00185         *    Destructor
00186         */
00187         inline ~Time();
00188 
00189         /**
00190         *  @brief
00191         *    Get the year
00192         *
00193         *  @return
00194         *    Year
00195         */
00196         inline uint16 GetYear() const;
00197 
00198         /**
00199         *  @brief
00200         *    Set the year
00201         *
00202         *  @param[in] nYear
00203         *    Year
00204         */
00205         inline void SetYear(uint16 nYear);
00206 
00207         /**
00208         *  @brief
00209         *    Get the month
00210         *
00211         *  @return
00212         *    Month [January..December]
00213         */
00214         inline EMonth GetMonth() const;
00215 
00216         /**
00217         *  @brief
00218         *    Set the month
00219         *
00220         *  @param[in] nMonth
00221         *    Month [January..December]
00222         */
00223         inline void SetMonth(EMonth nMonth);
00224 
00225         /**
00226         *  @brief
00227         *    Get the day of the month
00228         *
00229         *  @return
00230         *    Day of the month [1..31]
00231         */
00232         inline uint8 GetDayOfMonth() const;
00233 
00234         /**
00235         *  @brief
00236         *    Set the day of the month
00237         *
00238         *  @param[in] nDayOfMonth
00239         *    Day of the month [1..31]
00240         */
00241         inline void SetDayOfMonth(uint8 nDayOfMonth);
00242 
00243         /**
00244         *  @brief
00245         *    Get the day of the week
00246         *
00247         *  @return
00248         *    Day of the week [Sunday..Saturday]
00249         */
00250         inline EDay GetDayOfWeek() const;
00251 
00252         /**
00253         *  @brief
00254         *    Set the day of the week
00255         *
00256         *  @param[in] nDayOfWeek
00257         *    Day of the week [Sunday..Saturday]
00258         */
00259         inline void SetDayOfWeek(EDay nDayOfWeek);
00260 
00261         /**
00262         *  @brief
00263         *    Get the hour
00264         *
00265         *  @return
00266         *    Hour [0..23]
00267         */
00268         inline uint8 GetHour() const;
00269 
00270         /**
00271         *  @brief
00272         *    Set the hour
00273         *
00274         *  @param[in] nHour
00275         *    Hour [0..23]
00276         */
00277         inline void SetHour(uint8 nHour);
00278 
00279         /**
00280         *  @brief
00281         *    Get the minute
00282         *
00283         *  @return
00284         *    Minute [0..59]
00285         */
00286         inline uint8 GetMinute() const;
00287 
00288         /**
00289         *  @brief
00290         *    Set the minute
00291         *
00292         *  @param[in] nMinute
00293         *    Minute [0..59]
00294         */
00295         inline void SetMinute(uint8 nMinute);
00296 
00297         /**
00298         *  @brief
00299         *    Get the second
00300         *
00301         *  @return
00302         *    Second [0..59]
00303         */
00304         inline uint8 GetSecond() const;
00305 
00306         /**
00307         *  @brief
00308         *    Set the second
00309         *
00310         *  @param[in] nSecond
00311         *    Second [0..59]
00312         */
00313         inline void SetSecond(uint8 nSecond);
00314 
00315         /**
00316         *  @brief
00317         *    Get the millisecond
00318         *
00319         *  @return
00320         *    Millisecond [0..999]
00321         */
00322         inline uint16 GetMillisecond() const;
00323 
00324         /**
00325         *  @brief
00326         *    Set the millisecond
00327         *
00328         *  @param[in] nMillisecond
00329         *    Millisecond [0..999]
00330         */
00331         inline void SetMillisecond(uint16 nMillisecond);
00332 
00333         /**
00334         *  @brief
00335         *    Returns a string representation of the time
00336         *
00337         *  @return
00338         *    String representation (for example: Sun Sep 16 01:03:52 1973)
00339         */
00340         PLCORE_API String ToString() const;
00341 
00342         /**
00343         *  @brief
00344         *    Set time from string representation
00345         *
00346         *  @param[in] sString
00347         *    String representation (for example: Sun Sep 16 01:03:52 1973)
00348         */
00349         PLCORE_API void FromString(const String &sString);
00350 
00351         /**
00352         *  @brief
00353         *    Converts a date from Unix/POSIX format
00354         *
00355         *  @param[in] nUnixDate
00356         *    Date in Unix format
00357         */
00358         PLCORE_API void SetUnixDate(uint32 nUnixDate);
00359 
00360         /**
00361         *  @brief
00362         *    Converts a date from DOS format
00363         *
00364         *  @param[in] nDOSDate
00365         *    Date in DOS format
00366         */
00367         PLCORE_API void SetDOSDate(uint32 nDOSDate);
00368 
00369         //[-------------------------------------------------------]
00370         //[ Comparison                                            ]
00371         //[-------------------------------------------------------]
00372         PLCORE_API bool operator ==(const Time &cTime) const;
00373         PLCORE_API bool operator !=(const Time &cTime) const;
00374 
00375 
00376     //[-------------------------------------------------------]
00377     //[ Private data                                          ]
00378     //[-------------------------------------------------------]
00379     private:
00380         uint16 m_nYear;         /**< Years */
00381         EMonth m_nMonth;        /**< Month of the year - [January..December] */
00382         uint8  m_nDayOfMonth;   /**< Day of the month - [1..31] */
00383         EDay   m_nDayOfWeek;    /**< Day of the week - [Sunday..Saturday] */
00384         uint8  m_nHour;         /**< Hours since midnight - [0..23] */
00385         uint8  m_nMinute;       /**< Minutes after the hour - [0..59] */
00386         uint8  m_nSecond;       /**< Seconds after the minute - [0..59] */
00387         uint16 m_nMillisecond;  /**< Milliseconds after the second - [0..999] */
00388 
00389 
00390 };
00391 
00392 
00393 //[-------------------------------------------------------]
00394 //[ Namespace                                             ]
00395 //[-------------------------------------------------------]
00396 } // PLCore
00397 
00398 
00399 //[-------------------------------------------------------]
00400 //[ Implementation                                        ]
00401 //[-------------------------------------------------------]
00402 #include "PLCore/Tools/Time.inl"
00403 
00404 
00405 #endif // __PLCORE_TIME_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:09:01
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported