datetime.h Source File - ClanLib SDK
Description: datetime.h Source File

datetime.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 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** Harry Storbacka
29*/
30
31#pragma once
32
33#include "../System/cl_platform.h"
34
35namespace clan
36{
39
41 class DateTime
42 {
43 public:
44 enum TimeZone
45 {
46 local_timezone,
47 utc_timezone
48 };
49
51 DateTime();
52 DateTime(int year, int month, int day, int hour = 0, int minute = 0, int seconds = 0, int nanoseconds = 0, TimeZone timezone = utc_timezone);
53 ~DateTime();
54
56 static DateTime get_current_local_time();
57
59 static DateTime get_current_utc_time();
60
62 static DateTime get_local_time_from_ticks(int64_t ticks);
63
65 static DateTime get_utc_time_from_ticks(int64_t ticks);
66
67 static DateTime from_short_date_string(const std::string &value);
68
69 bool is_null() const;
70 unsigned short get_year() const;
71
75 unsigned char get_month() const;
76 unsigned char get_day() const;
77 unsigned char get_hour() const;
78 unsigned char get_minutes() const;
79 unsigned char get_seconds() const;
80 unsigned int get_nanoseconds() const;
81 TimeZone get_timezone() const;
82
86 unsigned char get_week() const;
87
91 int get_difference_in_days(const DateTime &other) const;
92
96 unsigned int get_day_of_week() const;
97
101 static int get_days_in_month(int month, int year);
102
103 void set_null();
104 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);
105 void set_year(int year);
106 void set_month(int month);
107 void set_day(int day);
108 void set_hour(int hour);
109 void set_minutes(int minutes);
110 void set_seconds(int seconds);
111 void set_nanoseconds(int nanoseconds);
112 void set_timezone(TimeZone timezone);
113
114 DateTime &add_years(int years);
115 DateTime &add_days(int days);
116 DateTime &add_months(int months);
117 /*
118 void add_hours(int hours);
119 void add_minutes(int minutes);
120 void add_seconds(int seconds);
121 void add_nanoseconds(int nanoseconds);
122 */
123 DateTime to_utc() const;
124 DateTime to_local() const;
125
127 int64_t to_ticks() const;
128
130 std::string to_long_date_string() const;
131
133 std::string to_short_date_string() const;
134
136 std::string to_short_datetime_string() const;
137
139 std::string to_long_time_string() const;
140
142 std::string to_short_time_string() const;
143
145 std::string to_string() const;
146
147 bool operator <(const DateTime &other) const;
148 bool operator <=(const DateTime &other) const;
149 bool operator >(const DateTime &other) const;
150 bool operator >=(const DateTime &other) const;
151 bool operator ==(const DateTime &other) const;
152 bool operator !=(const DateTime &other) const;
153
154 private:
155 void throw_if_invalid_date(int year, int month, int day, int hour, int minute, int seconds, int nanoseconds) const;
156 void throw_if_null() const;
157
158 int get_day_number() const;
159 void set_date_from_daynumber(int g);
160
161 unsigned short year;
162 unsigned char month;
163 unsigned char day;
164 unsigned char hour;
165 unsigned char minute;
166 unsigned char seconds;
167 unsigned int nanoseconds;
168
169 TimeZone timezone;
170 static const int64_t ticks_from_1601_to_1900;
171 };
172
174}
clan::DateTime
Date/Time class.
Definition datetime.h:42
clan::DateTime::get_days_in_month
static int get_days_in_month(int month, int year)
Returns the number of days in the given month.
clan::DateTime::operator==
bool operator==(const DateTime &other) const
clan::DateTime::get_hour
unsigned char get_hour() const
clan::DateTime::operator>
bool operator>(const DateTime &other) const
clan::DateTime::set_minutes
void set_minutes(int minutes)
clan::DateTime::operator<
bool operator<(const DateTime &other) const
clan::DateTime::set_seconds
void set_seconds(int seconds)
clan::DateTime::get_seconds
unsigned char get_seconds() const
clan::DateTime::set_year
void set_year(int year)
clan::DateTime::set_null
void set_null()
clan::DateTime::to_short_date_string
std::string to_short_date_string() const
yyyy-mm-dd
clan::DateTime::get_utc_time_from_ticks
static DateTime get_utc_time_from_ticks(int64_t ticks)
Converts a time tick value (number of 100-nanosecond intervals since January 1, 1601 UTC) to a date t...
clan::DateTime::to_string
std::string to_string() const
Mon Feb 3 12:32:54 2008.
clan::DateTime::get_current_utc_time
static DateTime get_current_utc_time()
Get current system time in UTC.
clan::DateTime::operator!=
bool operator!=(const DateTime &other) const
clan::DateTime::get_week
unsigned char get_week() const
Returns the ISO 8601 week number of the date.
clan::DateTime::set_timezone
void set_timezone(TimeZone timezone)
clan::DateTime::get_difference_in_days
int get_difference_in_days(const DateTime &other) const
Returns the difference in days between two dates. This function is only accurate for the next few mil...
clan::DateTime::set_month
void set_month(int month)
clan::DateTime::add_months
DateTime & add_months(int months)
clan::DateTime::operator<=
bool operator<=(const DateTime &other) const
clan::DateTime::to_utc
DateTime to_utc() const
clan::DateTime::DateTime
DateTime(int year, int month, int day, int hour=0, int minute=0, int seconds=0, int nanoseconds=0, TimeZone timezone=utc_timezone)
clan::DateTime::add_days
DateTime & add_days(int days)
clan::DateTime::~DateTime
~DateTime()
clan::DateTime::to_long_time_string
std::string to_long_time_string() const
hh:mm:ss
clan::DateTime::get_month
unsigned char get_month() const
Returns the month number in range 1-12.
clan::DateTime::to_ticks
int64_t to_ticks() const
Converts the date to the number of 100-nanosecond intervals since January 1, 1601 UTC.
clan::DateTime::get_minutes
unsigned char get_minutes() const
clan::DateTime::set_hour
void set_hour(int hour)
clan::DateTime::get_year
unsigned short get_year() const
clan::DateTime::TimeZone
TimeZone
Definition datetime.h:45
clan::DateTime::utc_timezone
@ utc_timezone
Definition datetime.h:47
clan::DateTime::local_timezone
@ local_timezone
Definition datetime.h:46
clan::DateTime::to_long_date_string
std::string to_long_date_string() const
Mon Mar 3 2007.
clan::DateTime::set_day
void set_day(int day)
clan::DateTime::from_short_date_string
static DateTime from_short_date_string(const std::string &value)
clan::DateTime::DateTime
DateTime()
Constructs a date/time object.
clan::DateTime::get_current_local_time
static DateTime get_current_local_time()
Get current system time in local time zone.
clan::DateTime::set_date
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)
clan::DateTime::get_day
unsigned char get_day() const
clan::DateTime::to_local
DateTime to_local() const
clan::DateTime::is_null
bool is_null() const
clan::DateTime::add_years
DateTime & add_years(int years)
clan::DateTime::get_timezone
TimeZone get_timezone() const
clan::DateTime::get_nanoseconds
unsigned int get_nanoseconds() const
clan::DateTime::set_nanoseconds
void set_nanoseconds(int nanoseconds)
clan::DateTime::to_short_datetime_string
std::string to_short_datetime_string() const
yyyy-mm-dd hh:mm:ss
clan::DateTime::get_day_of_week
unsigned int get_day_of_week() const
Get the day of the week.
clan::DateTime::operator>=
bool operator>=(const DateTime &other) const
clan::DateTime::to_short_time_string
std::string to_short_time_string() const
hh:mm
clan::DateTime::get_local_time_from_ticks
static DateTime get_local_time_from_ticks(int64_t ticks)
Converts a time tick value (number of 100-nanosecond intervals since January 1, 1601 UTC) to a date t...
clan
Definition clanapp.h:36
clan::Key::g
@ g