datetime.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2011 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 "../System/cl_platform.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_byte64 ticks);
00066 
00068         static CL_DateTime get_utc_time_from_ticks(cl_byte64 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 
00083         unsigned char get_month() const;
00084         unsigned char get_day() const;
00085         unsigned char get_hour() const;
00086         unsigned char get_minutes() const;
00087         unsigned char get_seconds() const;
00088         unsigned int get_nanoseconds() const;
00089         TimeZone get_timezone() const;
00090 
00094         unsigned int get_day_of_week() const;
00096 
00099 public:
00100         void set_null();
00101         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);
00102         void set_year(int year);
00103         void set_month(int month);
00104         void set_day(int day);
00105         void set_hour(int hour);
00106         void set_minutes(int minutes);
00107         void set_seconds(int seconds);
00108         void set_nanoseconds(int nanoseconds);
00109         void set_timezone(TimeZone timezone);
00110 /*
00111         void add_years(int years);
00112         void add_days(int days);
00113         void add_months(int months);
00114         void add_hours(int hours);
00115         void add_minutes(int minutes);
00116         void add_seconds(int seconds);
00117         void add_nanoseconds(int nanoseconds);
00118 */
00119         CL_DateTime to_utc() const;
00120         CL_DateTime to_local() const;
00121 
00123         cl_byte64 to_ticks() const;
00124 
00126         CL_String to_long_date_string() const;
00127 
00129         CL_String to_short_date_string() const;
00130 
00132         CL_String to_short_datetime_string() const;
00133 
00135         CL_String to_long_time_string() const;
00136 
00138         CL_String to_short_time_string() const;
00139 
00141         CL_String to_string() const;
00142 
00143         bool operator <(const CL_DateTime &other) const;
00144         bool operator <=(const CL_DateTime &other) const;
00145         bool operator >(const CL_DateTime &other) const;
00146         bool operator >=(const CL_DateTime &other) const;
00147         bool operator ==(const CL_DateTime &other) const;
00148         bool operator !=(const CL_DateTime &other) const;
00150 
00153 private:
00154         void throw_if_invalid_date(int year, int month, int day, int hour, int minute, int seconds, int nanoseconds) const;
00155         void throw_if_null() const;
00156 
00157         unsigned short year;
00158         unsigned char month;
00159         unsigned char day;
00160         unsigned char hour;
00161         unsigned char minute;
00162         unsigned char seconds;
00163         unsigned int nanoseconds;
00164 
00165         TimeZone timezone;
00166         static const cl_byte64 ticks_from_1601_to_1900;
00168 };