4 * Copyright (C) 2005-2013 Team XBMC
7 * This Program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This Program 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.
17 * You should have received a copy of the GNU General Public License
18 * along with XBMC; see the file COPYING. If not, see
19 * <http://www.gnu.org/licenses/>.
23 #include "utils/Archive.h"
25 /*! \brief TIME_FORMAT enum/bitmask used for formatting time strings
26 Note the use of bitmasking, e.g.
27 TIME_FORMAT_HH_MM_SS = TIME_FORMAT_HH | TIME_FORMAT_MM | TIME_FORMAT_SS
28 \sa StringUtils::SecondsToTimeString
30 enum TIME_FORMAT { TIME_FORMAT_GUESS = 0,
33 TIME_FORMAT_MM_SS = 3,
35 TIME_FORMAT_HH_SS = 5, // not particularly useful
36 TIME_FORMAT_HH_MM = 6,
37 TIME_FORMAT_HH_MM_SS = 7,
38 TIME_FORMAT_XX = 8, // AM/PM
39 TIME_FORMAT_HH_MM_XX = 14,
40 TIME_FORMAT_HH_MM_SS_XX = 15,
42 TIME_FORMAT_H_MM_SS = 19,
43 TIME_FORMAT_H_MM_SS_XX = 27};
51 CDateTimeSpan(const CDateTimeSpan& span);
52 CDateTimeSpan(int day, int hour, int minute, int second);
54 bool operator >(const CDateTimeSpan& right) const;
55 bool operator >=(const CDateTimeSpan& right) const;
56 bool operator <(const CDateTimeSpan& right) const;
57 bool operator <=(const CDateTimeSpan& right) const;
58 bool operator ==(const CDateTimeSpan& right) const;
59 bool operator !=(const CDateTimeSpan& right) const;
61 CDateTimeSpan operator +(const CDateTimeSpan& right) const;
62 CDateTimeSpan operator -(const CDateTimeSpan& right) const;
64 const CDateTimeSpan& operator +=(const CDateTimeSpan& right);
65 const CDateTimeSpan& operator -=(const CDateTimeSpan& right);
67 void SetDateTimeSpan(int day, int hour, int minute, int second);
68 void SetFromPeriod(const CStdString &period);
69 void SetFromTimeString(const CStdString& time);
73 int GetMinutes() const;
74 int GetSeconds() const;
75 int GetSecondsTotal() const;
78 void ToULargeInt(ULARGE_INTEGER& time) const;
79 void FromULargeInt(const ULARGE_INTEGER& time);
84 friend class CDateTime;
87 /// \brief DateTime class, which uses FILETIME as it's base.
88 class CDateTime : public IArchivable
92 CDateTime(const CDateTime& time);
93 CDateTime(const SYSTEMTIME& time);
94 CDateTime(const FILETIME& time);
95 CDateTime(const time_t& time);
96 CDateTime(const tm& time);
97 CDateTime(int year, int month, int day, int hour, int minute, int second);
98 virtual ~CDateTime() {}
100 void SetFromDateString(const CStdString &date);
102 static CDateTime GetCurrentDateTime();
103 static CDateTime GetUTCDateTime();
104 static int MonthStringToMonthNum(const CStdString& month);
106 const CDateTime& operator =(const SYSTEMTIME& right);
107 const CDateTime& operator =(const FILETIME& right);
108 const CDateTime& operator =(const time_t& right);
109 const CDateTime& operator =(const tm& right);
111 bool operator >(const CDateTime& right) const;
112 bool operator >=(const CDateTime& right) const;
113 bool operator <(const CDateTime& right) const;
114 bool operator <=(const CDateTime& right) const;
115 bool operator ==(const CDateTime& right) const;
116 bool operator !=(const CDateTime& right) const;
118 bool operator >(const FILETIME& right) const;
119 bool operator >=(const FILETIME& right) const;
120 bool operator <(const FILETIME& right) const;
121 bool operator <=(const FILETIME& right) const;
122 bool operator ==(const FILETIME& right) const;
123 bool operator !=(const FILETIME& right) const;
125 bool operator >(const SYSTEMTIME& right) const;
126 bool operator >=(const SYSTEMTIME& right) const;
127 bool operator <(const SYSTEMTIME& right) const;
128 bool operator <=(const SYSTEMTIME& right) const;
129 bool operator ==(const SYSTEMTIME& right) const;
130 bool operator !=(const SYSTEMTIME& right) const;
132 bool operator >(const time_t& right) const;
133 bool operator >=(const time_t& right) const;
134 bool operator <(const time_t& right) const;
135 bool operator <=(const time_t& right) const;
136 bool operator ==(const time_t& right) const;
137 bool operator !=(const time_t& right) const;
139 bool operator >(const tm& right) const;
140 bool operator >=(const tm& right) const;
141 bool operator <(const tm& right) const;
142 bool operator <=(const tm& right) const;
143 bool operator ==(const tm& right) const;
144 bool operator !=(const tm& right) const;
146 CDateTime operator +(const CDateTimeSpan& right) const;
147 CDateTime operator -(const CDateTimeSpan& right) const;
149 const CDateTime& operator +=(const CDateTimeSpan& right);
150 const CDateTime& operator -=(const CDateTimeSpan& right);
152 CDateTimeSpan operator -(const CDateTime& right) const;
154 operator FILETIME() const;
156 virtual void Archive(CArchive& ar);
161 int GetMonth() const;
164 int GetMinute() const;
165 int GetSecond() const;
166 int GetDayOfWeek() const;
167 int GetMinuteOfDay() const;
169 void SetDateTime(int year, int month, int day, int hour, int minute, int second);
170 void SetDate(int year, int month, int day);
171 void SetTime(int hour, int minute, int second);
172 void SetFromDBDate(const CStdString &date);
173 void SetFromDBTime(const CStdString &time);
174 void SetFromW3CDate(const CStdString &date);
175 void SetFromUTCDateTime(const CDateTime &dateTime);
176 void SetFromUTCDateTime(const time_t &dateTime);
177 void SetFromRFC1123DateTime(const CStdString &dateTime);
179 /*! \brief set from a database datetime format YYYY-MM-DD HH:MM:SS
180 \sa GetAsDBDateTime()
182 void SetFromDBDateTime(const CStdString &dateTime);
184 void GetAsSystemTime(SYSTEMTIME& time) const;
185 void GetAsTime(time_t& time) const;
186 void GetAsTm(tm& time) const;
187 void GetAsTimeStamp(FILETIME& time) const;
189 CDateTime GetAsUTCDateTime() const;
190 CStdString GetAsSaveString() const;
191 CStdString GetAsDBDateTime() const;
192 CStdString GetAsDBDate() const;
193 CStdString GetAsLocalizedDate(bool longDate=false, bool withShortNames=true) const;
194 CStdString GetAsLocalizedDate(const CStdString &strFormat, bool withShortNames=true) const;
195 CStdString GetAsLocalizedTime(const CStdString &format, bool withSeconds=true) const;
196 CStdString GetAsLocalizedDateTime(bool longDate=false, bool withSeconds=true) const;
197 CStdString GetAsRFC1123DateTime() const;
199 void SetValid(bool yesNo);
200 bool IsValid() const;
202 static void ResetTimezoneBias(void);
203 static CDateTimeSpan GetTimezoneBias(void);
206 bool ToFileTime(const SYSTEMTIME& time, FILETIME& fileTime) const;
207 bool ToFileTime(const time_t& time, FILETIME& fileTime) const;
208 bool ToFileTime(const tm& time, FILETIME& fileTime) const;
210 void ToULargeInt(ULARGE_INTEGER& time) const;
211 void FromULargeInt(const ULARGE_INTEGER& time);