4 * Copyright (C) 2005-2012 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,
41 TIME_FORMAT_H_MM_SS = 19};
49 CDateTimeSpan(const CDateTimeSpan& span);
50 CDateTimeSpan(int day, int hour, int minute, int second);
52 bool operator >(const CDateTimeSpan& right) const;
53 bool operator >=(const CDateTimeSpan& right) const;
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;
59 CDateTimeSpan operator +(const CDateTimeSpan& right) const;
60 CDateTimeSpan operator -(const CDateTimeSpan& right) const;
62 const CDateTimeSpan& operator +=(const CDateTimeSpan& right);
63 const CDateTimeSpan& operator -=(const CDateTimeSpan& right);
65 void SetDateTimeSpan(int day, int hour, int minute, int second);
66 void SetFromPeriod(const CStdString &period);
67 void SetFromTimeString(const CStdString& time);
71 int GetMinutes() const;
72 int GetSeconds() const;
75 void ToULargeInt(ULARGE_INTEGER& time) const;
76 void FromULargeInt(const ULARGE_INTEGER& time);
81 friend class CDateTime;
84 /// \brief DateTime class, which uses FILETIME as it's base.
85 class CDateTime : public IArchivable
89 CDateTime(const CDateTime& time);
90 CDateTime(const SYSTEMTIME& time);
91 CDateTime(const FILETIME& time);
92 CDateTime(const time_t& time);
93 CDateTime(const tm& time);
94 CDateTime(int year, int month, int day, int hour, int minute, int second);
95 virtual ~CDateTime() {}
97 void SetFromDateString(const CStdString &date);
99 static CDateTime GetCurrentDateTime();
100 static CDateTime GetUTCDateTime();
101 static int MonthStringToMonthNum(const CStdString& month);
103 const CDateTime& operator =(const SYSTEMTIME& right);
104 const CDateTime& operator =(const FILETIME& right);
105 const CDateTime& operator =(const time_t& right);
106 const CDateTime& operator =(const tm& right);
108 bool operator >(const CDateTime& right) const;
109 bool operator >=(const CDateTime& right) const;
110 bool operator <(const CDateTime& right) const;
111 bool operator <=(const CDateTime& right) const;
112 bool operator ==(const CDateTime& right) const;
113 bool operator !=(const CDateTime& right) const;
115 bool operator >(const FILETIME& right) const;
116 bool operator >=(const FILETIME& right) const;
117 bool operator <(const FILETIME& right) const;
118 bool operator <=(const FILETIME& right) const;
119 bool operator ==(const FILETIME& right) const;
120 bool operator !=(const FILETIME& right) const;
122 bool operator >(const SYSTEMTIME& right) const;
123 bool operator >=(const SYSTEMTIME& right) const;
124 bool operator <(const SYSTEMTIME& right) const;
125 bool operator <=(const SYSTEMTIME& right) const;
126 bool operator ==(const SYSTEMTIME& right) const;
127 bool operator !=(const SYSTEMTIME& right) const;
129 bool operator >(const time_t& right) const;
130 bool operator >=(const time_t& right) const;
131 bool operator <(const time_t& 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;
136 bool operator >(const tm& right) const;
137 bool operator >=(const tm& right) const;
138 bool operator <(const tm& right) const;
139 bool operator <=(const tm& right) const;
140 bool operator ==(const tm& right) const;
141 bool operator !=(const tm& right) const;
143 CDateTime operator +(const CDateTimeSpan& right) const;
144 CDateTime operator -(const CDateTimeSpan& right) const;
146 const CDateTime& operator +=(const CDateTimeSpan& right);
147 const CDateTime& operator -=(const CDateTimeSpan& right);
149 CDateTimeSpan operator -(const CDateTime& right) const;
151 operator FILETIME() const;
153 virtual void Archive(CArchive& ar);
158 int GetMonth() const;
161 int GetMinute() const;
162 int GetSecond() const;
163 int GetDayOfWeek() const;
164 int GetMinuteOfDay() const;
166 void SetDateTime(int year, int month, int day, int hour, int minute, int second);
167 void SetDate(int year, int month, int day);
168 void SetTime(int hour, int minute, int second);
169 void SetFromDBDate(const CStdString &date);
170 void SetFromDBTime(const CStdString &time);
171 void SetFromW3CDate(const CStdString &date);
172 void SetFromUTCDateTime(const CDateTime &dateTime);
173 void SetFromUTCDateTime(const time_t &dateTime);
174 void SetFromRFC1123DateTime(const CStdString &dateTime);
176 /*! \brief set from a database datetime format YYYY-MM-DD HH:MM:SS
177 \sa GetAsDBDateTime()
179 void SetFromDBDateTime(const CStdString &dateTime);
181 void GetAsSystemTime(SYSTEMTIME& time) const;
182 void GetAsTime(time_t& time) const;
183 void GetAsTm(tm& time) const;
184 void GetAsTimeStamp(FILETIME& time) const;
186 CDateTime GetAsUTCDateTime() const;
187 CStdString GetAsSaveString() const;
188 CStdString GetAsDBDateTime() const;
189 CStdString GetAsDBDate() const;
190 CStdString GetAsLocalizedDate(bool longDate=false, bool withShortNames=true) const;
191 CStdString GetAsLocalizedDate(const CStdString &strFormat, bool withShortNames=true) const;
192 CStdString GetAsLocalizedTime(const CStdString &format, bool withSeconds=true) const;
193 CStdString GetAsLocalizedDateTime(bool longDate=false, bool withSeconds=true) const;
194 CStdString GetAsRFC1123DateTime() const;
196 void SetValid(bool yesNo);
197 bool IsValid() const;
199 static void ResetTimezoneBias(void);
200 static CDateTimeSpan GetTimezoneBias(void);
203 bool ToFileTime(const SYSTEMTIME& time, FILETIME& fileTime) const;
204 bool ToFileTime(const time_t& time, FILETIME& fileTime) const;
205 bool ToFileTime(const tm& time, FILETIME& fileTime) const;
207 void ToULargeInt(ULARGE_INTEGER& time) const;
208 void FromULargeInt(const ULARGE_INTEGER& time);