datetime.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2009 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 may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 **    Kenneth Gangstoe
00028 */
00029 
00032 
00033 
00034 #pragma once
00035 
00036 #include "../api_core.h"
00037 #include "../IOData/datatypes.h"
00038 
00042 class CL_API_CORE CL_DateTime
00043 {
00046 public:
00047         enum TimeZone
00048         {
00049                 local_timezone,
00050                 utc_timezone
00051         };
00052 
00054         CL_DateTime();
00055         CL_DateTime(int year, int month, int day, int hour = 0, int minute = 0, int seconds = 0, int nanoseconds = 0, TimeZone timezone=utc_timezone);
00056         ~CL_DateTime();
00057 
00059         static CL_DateTime get_current_local_time();
00060 
00062         static CL_DateTime get_current_utc_time();
00063 
00065         static CL_DateTime get_local_time_from_ticks(cl_int64 ticks);
00066 
00068         static CL_DateTime get_utc_time_from_ticks(cl_int64 ticks);
00069 
00070         static CL_DateTime from_short_date_string(const CL_String &value);
00071 
00073 
00076 public:
00077         bool is_null() const;
00078         unsigned short get_year() const;
00079         unsigned char get_month() const;
00080         unsigned char get_day() const;
00081         unsigned char get_hour() const;
00082         unsigned char get_minutes() const;
00083         unsigned char get_seconds() const;
00084         unsigned int get_nanoseconds() const;
00085         TimeZone get_timezone() const;
00086 
00090         unsigned int get_day_of_week() const;
00092 
00095 public:
00096         void set_null();
00097         void set_date(int year, int month, int day, int hour = 0, int minute = 0, int seconds = 0, int nanoseconds = 0, TimeZone timezone = utc_timezone);
00098         void set_year(int year);
00099         void set_month(int month);
00100         void set_day(int day);
00101         void set_hour(int hour);
00102         void set_minutes(int minutes);
00103         void set_seconds(int seconds);
00104         void set_nanoseconds(int nanoseconds);
00105         void set_timezone(TimeZone timezone);
00106 /*
00107         void add_years(int years);
00108         void add_days(int days);
00109         void add_months(int months);
00110         void add_hours(int hours);
00111         void add_minutes(int minutes);
00112         void add_seconds(int seconds);
00113         void add_nanoseconds(int nanoseconds);
00114 */
00115         CL_DateTime to_utc() const;
00116         CL_DateTime to_local() const;
00117 
00119         cl_int64 to_ticks() const;
00120 
00122         CL_String to_long_date_string() const;
00123 
00125         CL_String to_short_date_string() const;
00126 
00128         CL_String to_short_datetime_string() const;
00129 
00131         CL_String to_long_time_string() const;
00132 
00134         CL_String to_short_time_string() const;
00135 
00137         CL_String to_string() const;
00138 
00139         bool operator <(const CL_DateTime &other) const;
00140         bool operator <=(const CL_DateTime &other) const;
00141         bool operator >(const CL_DateTime &other) const;
00142         bool operator >=(const CL_DateTime &other) const;
00143         bool operator ==(const CL_DateTime &other) const;
00144         bool operator !=(const CL_DateTime &other) const;
00146 
00149 private:
00150         void throw_if_invalid_date(int year, int month, int day, int hour, int minute, int seconds, int nanoseconds) const;
00151         void throw_if_null() const;
00152 
00153         unsigned short year;
00154         unsigned char month;
00155         unsigned char day;
00156         unsigned char hour;
00157         unsigned char minute;
00158         unsigned char seconds;
00159         unsigned int nanoseconds;
00160 
00161         TimeZone timezone;
00162         static const cl_int64 ticks_from_1601_to_1900;
00164 };

Generated on Thu Dec 3 02:39:28 2009 for ClanLib by  doxygen 1.4.6