Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

datetime.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2005 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 */
00028 
00029 #ifndef header_datetime
00030 #define header_datetime
00031 
00032 #include <time.h>
00033 #include "Mutex.h"
00034 
00035 class CL_DateTime
00036 {
00038 public:
00039         CL_DateTime();
00040 
00041         CL_DateTime(time_t unix_time);
00042         
00043         CL_DateTime(const CL_DateTime &other);
00044 
00045         ~CL_DateTime();
00046 
00047         //: Get current system time.
00048         static CL_DateTime get_system_time();
00049 
00051 public:
00052         //: Seconds since 00:00:00 on January 1, 1970 in Coordinated Universal Time (UTC)
00053         time_t get_unix_time() const;
00054 
00055         //: Seconds in local time zone
00056         int get_seconds_local() const;
00057         
00058         //: Seconds in UTC
00059         int get_seconds_utc() const;
00060         
00061         //: Minutes in local time zone
00062         int get_minutes_local() const;
00063         
00064         //: Minutes in UTC
00065         int get_minutes_utc() const;
00066         
00067         //: Hours in local time zone
00068         int get_hours_local() const;
00069         
00070         //: Hours in UTC
00071         int get_hours_utc() const;
00072         
00073         //: Day of the month in local time zone
00074         int get_month_day_local() const;
00075 
00076         //: Day of the month in UTC
00077         int get_month_day_utc() const;
00078 
00079         //: Month in local time zone
00080         int get_month_local() const;
00081         
00082         //: Month in UTC
00083         int get_month_utc() const;
00084         
00085         //: Year in local time zone
00086         int get_year_local() const;
00087         
00088         //: Year in UTC
00089         int get_year_utc() const;
00090         
00091         //: Day of the week
00092         int get_week_day_local() const;
00093 
00094         //: Day of the week
00095         int get_week_day_utc() const;
00096 
00097         //: Day in the year in local time zone
00098         int get_year_day_local() const;
00099         
00100         //: Day in the year in UTC
00101         int get_year_day_utc() const;
00102         
00103         //: Daylight saving time
00104         //- <p>The value is positive if daylight saving time is in effect,
00105         //- zero if it is not, and negative if the information is not
00106         //- available.</p>
00107         int get_daylight_saving_time_local() const;
00108 
00109         //: Local time zone abbreviation
00110         CL_String get_zone_abbreviation() const;
00111 
00113 public:
00114         //: Seconds since 00:00:00 on January 1, 1970 in Coordinated Universal Time (UTC)
00115         void set_unix_time(time_t t);
00116 
00117         //: Seconds in local time zone
00118         void set_seconds_local(int seconds);
00119         
00120         //: Minutes in local time zone
00121         void set_minutes_local(int minutes);
00122         
00123         //: Hours in local time zone
00124         void set_hours_local(int hours);
00125         
00126         //: Day of the month in local time zone
00127         void set_month_day_local(int day);
00128 
00129         //: Month in local time zone
00130         void set_month_local(int month);
00131         
00132         //: Year in local time zone
00133         void set_year_local(int year);
00134 
00135         //: Save broken-down time to unix time.
00136         void save_local();
00137 
00138         CL_DateTime &operator =(const CL_DateTime &other);
00139 
00140         bool operator <(const CL_DateTime &other) const;
00141 
00142         bool operator <=(const CL_DateTime &other) const;
00143         
00144         bool operator >(const CL_DateTime &other) const;
00145 
00146         bool operator >=(const CL_DateTime &other) const;
00147         
00148         bool operator ==(const CL_DateTime &other) const;
00149 
00150         bool operator !=(const CL_DateTime &other) const;
00151         
00153 private:
00154         void load_local() const;
00155         
00156         void load_utc() const;
00157         
00158         time_t unix_time;
00159 
00160         mutable struct tm *tm_local;
00161         
00162         mutable struct tm *tm_utc;
00163 
00164 #ifdef WIN32
00165         static CL_Mutex mutex;
00166 #endif
00167 };
00168 
00169 #endif

Generated on Sat Feb 19 22:51:15 2005 for npcore by  doxygen 1.4.1