xoreos  0.0.5
datetime.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef COMMON_TIME_H
26 #define COMMON_TIME_H
27 
28 #include <boost/date_time/posix_time/posix_time.hpp>
29 
30 #include "src/common/types.h"
31 #include "src/common/ustring.h"
32 
33 namespace Common {
34 
36 class DateTime : public boost::posix_time::ptime {
37 public:
38  enum TimeZone {
39  kUTC,
41  };
42 
52  DateTime(TimeZone zone);
60  DateTime(const UString &value);
61 
63  uint16 getYear () const { return date().year(); }
65  uint8 getMonth() const { return date().month(); }
67  uint8 getDay () const { return date().day(); }
68 
70  uint8 getHour () const { return time_of_day().hours(); }
72  uint8 getMinute() const { return time_of_day().minutes(); }
74  uint8 getSecond() const { return time_of_day().seconds(); }
75 
77  void getDate(uint16 &year, uint8 &month, uint8 &day) const {
78  year = getYear();
79  month = getMonth();
80  day = getDay();
81  }
83  void getTime(uint8 &hour, uint8 &minute, uint8 &second) const {
84  hour = getHour();
85  minute = getMinute();
86  second = getSecond();
87  }
89  void getDateTime(uint16 &year, uint8 &month, uint8 &day, uint8 &hour, uint8 &minute, uint8 &second) const {
90  getDate(year, month , day);
91  getTime(hour, minute, second);
92  }
93 
107  UString formatDateISO(uint32 sep = 0) const;
108 
121  UString formatTimeISO(uint32 sep = 0) const;
122 
136  UString formatDateTimeISO(uint32 sep = 0, uint32 sepDate = 0, uint32 sepTime = 0) const;
137 };
138 
139 } // End of namespace Common
140 
141 #endif // COMMON_TIME_H
Definition: 2dafile.h:39
A class holding an UTF-8 string.
Definition: ustring.h:48
A date/time object, storing a specific point in time.
Definition: datetime.h:36
uint8_t uint8
Definition: types.h:200
UString formatDateTimeISO(uint32 sep=0, uint32 sepDate=0, uint32 sepTime=0) const
Return a string representation of the date and time in ISO 8601 format.
Definition: datetime.cpp:79
uint8 getSecond() const
Return the second (0..60).
Definition: datetime.h:74
void getDateTime(uint16 &year, uint8 &month, uint8 &day, uint8 &hour, uint8 &minute, uint8 &second) const
Return the year, month (1..12), day (1..31), hour (0..23), minute (0..59) and second (0...
Definition: datetime.h:89
uint16_t uint16
Definition: types.h:202
uint16 getYear() const
Return the year in the Gregorian calendar.
Definition: datetime.h:63
The nondescript local time zone.
Definition: datetime.h:40
void getTime(uint8 &hour, uint8 &minute, uint8 &second) const
Return the hour in the 24-hour clock (0..23), minute (0..59) and second (0..60).
Definition: datetime.h:83
Low-level type definitions to handle fixed width types portably.
uint8 getMonth() const
Return the month in the Gregorian calendar (1..12).
Definition: datetime.h:65
UString formatDateISO(uint32 sep=0) const
Return a string representation of the date in ISO 8601 format.
Definition: datetime.cpp:61
Unicode string handling.
void getDate(uint16 &year, uint8 &month, uint8 &day) const
Return the year, month (1..12) and day (1..31) in the Gregorian calendar.
Definition: datetime.h:77
uint8 getHour() const
Return the hour in the 24-hour clock (0..23).
Definition: datetime.h:70
DateTime(TimeZone zone)
Create a DateTime object from the current date and time.
Definition: datetime.cpp:35
uint32_t uint32
Definition: types.h:204
Coordinated Universal Time (UTC).
Definition: datetime.h:39
uint8 getDay() const
Return the day in the Gregorian calendar (1..31).
Definition: datetime.h:67
uint8 getMinute() const
Return the minute (0..59).
Definition: datetime.h:72
UString formatTimeISO(uint32 sep=0) const
Return a string representation of the time in ISO 8601 format.
Definition: datetime.cpp:70