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/StdString.h"
24 #include "utils/Archive.h"
26 /*! \brief TIME_FORMAT enum/bitmask used for formatting time strings
27 Note the use of bitmasking, e.g.
28 TIME_FORMAT_HH_MM_SS = TIME_FORMAT_HH | TIME_FORMAT_MM | TIME_FORMAT_SS
29 \sa StringUtils::SecondsToTimeString
31 enum TIME_FORMAT { TIME_FORMAT_GUESS = 0,
34 TIME_FORMAT_MM_SS = 3,
36 TIME_FORMAT_HH_SS = 5, // not particularly useful
37 TIME_FORMAT_HH_MM = 6,
38 TIME_FORMAT_HH_MM_SS = 7,
39 TIME_FORMAT_XX = 8, // AM/PM
40 TIME_FORMAT_HH_MM_XX = 14,
41 TIME_FORMAT_HH_MM_SS_XX = 15,
43 TIME_FORMAT_H_MM_SS = 19,
44 TIME_FORMAT_H_MM_SS_XX = 27};
52 CDateTimeSpan(const CDateTimeSpan& span);
53 CDateTimeSpan(int day, int hour, int minute, int second);
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;
60 bool operator !=(const CDateTimeSpan& right) const;
62 CDateTimeSpan operator +(const CDateTimeSpan& right) const;
63 CDateTimeSpan operator -(const CDateTimeSpan& right) const;
65 const CDateTimeSpan& operator +=(const CDateTimeSpan& right);
66 const CDateTimeSpan& operator -=(const CDateTimeSpan& right);
68 void SetDateTimeSpan(int day, int hour, int minute, int second);
69 void SetFromPeriod(const CStdString &period);
70 void SetFromTimeString(const CStdString& time);
74 int GetMinutes() const;
75 int GetSeconds() const;
76 int GetSecondsTotal() const;
79 void ToULargeInt(ULARGE_INTEGER& time) const;
80 void FromULargeInt(const ULARGE_INTEGER& time);
85 friend class CDateTime;
88 /// \brief DateTime class, which uses FILETIME as it's base.
89 class CDateTime : public IArchivable
93 CDateTime(const CDateTime& time);
94 CDateTime(const SYSTEMTIME& time);
95 CDateTime(const FILETIME& time);
96 CDateTime(const time_t& time);
97 CDateTime(const tm& time);
98 CDateTime(int year, int month, int day, int hour, int minute, int second);
99 virtual ~CDateTime() {}
101 bool SetFromDateString(const CStdString &date);
103 static CDateTime GetCurrentDateTime();
104 static CDateTime GetUTCDateTime();
105 static int MonthStringToMonthNum(const CStdString& month);
107 const CDateTime& operator =(const SYSTEMTIME& right);
108 const CDateTime& operator =(const FILETIME& right);
109 const CDateTime& operator =(const time_t& right);
110 const CDateTime& operator =(const tm& right);
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;
117 bool operator !=(const CDateTime& 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;
124 bool operator !=(const FILETIME& 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;
131 bool operator !=(const SYSTEMTIME& 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;
138 bool operator !=(const time_t& 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;
145 bool operator !=(const tm& right) const;
147 CDateTime operator +(const CDateTimeSpan& right) const;
148 CDateTime operator -(const CDateTimeSpan& right) const;
150 const CDateTime& operator +=(const CDateTimeSpan& right);
151 const CDateTime& operator -=(const CDateTimeSpan& right);
153 CDateTimeSpan operator -(const CDateTime& right) const;
155 operator FILETIME() const;
157 virtual void Archive(CArchive& ar);
162 int GetMonth() const;
165 int GetMinute() const;
166 int GetSecond() const;
167 int GetDayOfWeek() const;
168 int GetMinuteOfDay() const;
170 bool SetDateTime(int year, int month, int day, int hour, int minute, int second);
171 bool SetDate(int year, int month, int day);
172 bool SetTime(int hour, int minute, int second);
173 bool SetFromDBDate(const CStdString &date);
174 bool SetFromDBTime(const CStdString &time);
175 bool SetFromW3CDate(const CStdString &date);
176 bool SetFromUTCDateTime(const CDateTime &dateTime);
177 bool SetFromUTCDateTime(const time_t &dateTime);
178 bool SetFromRFC1123DateTime(const CStdString &dateTime);
180 /*! \brief set from a database datetime format YYYY-MM-DD HH:MM:SS
181 \sa GetAsDBDateTime()
183 bool SetFromDBDateTime(const CStdString &dateTime);
185 void GetAsSystemTime(SYSTEMTIME& time) const;
186 void GetAsTime(time_t& time) const;
187 void GetAsTm(tm& time) const;
188 void GetAsTimeStamp(FILETIME& time) const;
190 CDateTime GetAsUTCDateTime() const;
191 CStdString GetAsSaveString() const;
192 CStdString GetAsDBDateTime() const;
193 CStdString GetAsDBDate() const;
194 CStdString GetAsLocalizedDate(bool longDate=false, bool withShortNames=true) const;
195 CStdString GetAsLocalizedDate(const CStdString &strFormat, bool withShortNames=true) const;
196 CStdString GetAsLocalizedTime(const CStdString &format, bool withSeconds=true) const;
197 CStdString GetAsLocalizedDateTime(bool longDate=false, bool withSeconds=true) const;
198 CStdString GetAsRFC1123DateTime() const;
200 void SetValid(bool yesNo);
201 bool IsValid() const;
203 static void ResetTimezoneBias(void);
204 static CDateTimeSpan GetTimezoneBias(void);
207 bool ToFileTime(const SYSTEMTIME& time, FILETIME& fileTime) const;
208 bool ToFileTime(const time_t& time, FILETIME& fileTime) const;
209 bool ToFileTime(const tm& time, FILETIME& fileTime) const;
211 void ToULargeInt(ULARGE_INTEGER& time) const;
212 void FromULargeInt(const ULARGE_INTEGER& time);