ClanLib  2.3.7
datetime.h
Go to the documentation of this file.
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2011 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Kenneth Gangstoe
28 */
29 
32 
33 
34 #pragma once
35 
36 #include "../api_core.h"
37 #include "../System/cl_platform.h"
38 
43 {
46 public:
47  enum TimeZone
48  {
50  utc_timezone
51  };
52 
54  CL_DateTime();
55  CL_DateTime(int year, int month, int day, int hour = 0, int minute = 0, int seconds = 0, int nanoseconds = 0, TimeZone timezone=utc_timezone);
56  ~CL_DateTime();
57 
59  static CL_DateTime get_current_local_time();
60 
62  static CL_DateTime get_current_utc_time();
63 
65  static CL_DateTime get_local_time_from_ticks(cl_byte64 ticks);
66 
68  static CL_DateTime get_utc_time_from_ticks(cl_byte64 ticks);
69 
70  static CL_DateTime from_short_date_string(const CL_String &value);
71 
73 
76 public:
77  bool is_null() const;
78  unsigned short get_year() const;
79 
83  unsigned char get_month() const;
84  unsigned char get_day() const;
85  unsigned char get_hour() const;
86  unsigned char get_minutes() const;
87  unsigned char get_seconds() const;
88  unsigned int get_nanoseconds() const;
89  TimeZone get_timezone() const;
90 
94  unsigned int get_day_of_week() const;
96 
99 public:
100  void set_null();
101  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);
102  void set_year(int year);
103  void set_month(int month);
104  void set_day(int day);
105  void set_hour(int hour);
106  void set_minutes(int minutes);
107  void set_seconds(int seconds);
108  void set_nanoseconds(int nanoseconds);
109  void set_timezone(TimeZone timezone);
110 /*
111  void add_years(int years);
112  void add_days(int days);
113  void add_months(int months);
114  void add_hours(int hours);
115  void add_minutes(int minutes);
116  void add_seconds(int seconds);
117  void add_nanoseconds(int nanoseconds);
118 */
119  CL_DateTime to_utc() const;
120  CL_DateTime to_local() const;
121 
123  cl_byte64 to_ticks() const;
124 
126  CL_String to_long_date_string() const;
127 
129  CL_String to_short_date_string() const;
130 
132  CL_String to_short_datetime_string() const;
133 
135  CL_String to_long_time_string() const;
136 
138  CL_String to_short_time_string() const;
139 
141  CL_String to_string() const;
142 
143  bool operator <(const CL_DateTime &other) const;
144  bool operator <=(const CL_DateTime &other) const;
145  bool operator >(const CL_DateTime &other) const;
146  bool operator >=(const CL_DateTime &other) const;
147  bool operator ==(const CL_DateTime &other) const;
148  bool operator !=(const CL_DateTime &other) const;
150 
153 private:
154  void throw_if_invalid_date(int year, int month, int day, int hour, int minute, int seconds, int nanoseconds) const;
155  void throw_if_null() const;
156 
157  unsigned short year;
158  unsigned char month;
159  unsigned char day;
160  unsigned char hour;
161  unsigned char minute;
162  unsigned char seconds;
163  unsigned int nanoseconds;
164 
165  TimeZone timezone;
166  static const cl_byte64 ticks_from_1601_to_1900;
168 };