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;
77 void ToULargeInt(ULARGE_INTEGER& time) const;
78 void FromULargeInt(const ULARGE_INTEGER& time);
83 friend class CDateTime;
86 /// \brief DateTime class, which uses FILETIME as it's base.
87 class CDateTime : public IArchivable
91 CDateTime(const CDateTime& time);
92 CDateTime(const SYSTEMTIME& time);
93 CDateTime(const FILETIME& time);
94 CDateTime(const time_t& time);
95 CDateTime(const tm& time);
96 CDateTime(int year, int month, int day, int hour, int minute, int second);
97 virtual ~CDateTime() {}
99 void SetFromDateString(const CStdString &date);
101 static CDateTime GetCurrentDateTime();
102 static CDateTime GetUTCDateTime();
103 static int MonthStringToMonthNum(const CStdString& month);
105 const CDateTime& operator =(const SYSTEMTIME& right);
106 const CDateTime& operator =(const FILETIME& right);
107 const CDateTime& operator =(const time_t& right);
108 const CDateTime& operator =(const tm& right);
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;
114 bool operator ==(const CDateTime& right) const;
115 bool operator !=(const CDateTime& 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;
121 bool operator ==(const FILETIME& right) const;
122 bool operator !=(const FILETIME& 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;
128 bool operator ==(const SYSTEMTIME& right) const;
129 bool operator !=(const SYSTEMTIME& 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;
135 bool operator ==(const time_t& right) const;
136 bool operator !=(const time_t& 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;
142 bool operator ==(const tm& right) const;
143 bool operator !=(const tm& right) const;
145 CDateTime operator +(const CDateTimeSpan& right) const;
146 CDateTime operator -(const CDateTimeSpan& right) const;
148 const CDateTime& operator +=(const CDateTimeSpan& right);
149 const CDateTime& operator -=(const CDateTimeSpan& right);
151 CDateTimeSpan operator -(const CDateTime& right) const;
153 operator FILETIME() const;
155 virtual void Archive(CArchive& ar);
160 int GetMonth() const;
163 int GetMinute() const;
164 int GetSecond() const;
165 int GetDayOfWeek() const;
166 int GetMinuteOfDay() const;
168 void SetDateTime(int year, int month, int day, int hour, int minute, int second);
169 void SetDate(int year, int month, int day);
170 void SetTime(int hour, int minute, int second);
171 void SetFromDBDate(const CStdString &date);
172 void SetFromDBTime(const CStdString &time);
173 void SetFromW3CDate(const CStdString &date);
174 void SetFromUTCDateTime(const CDateTime &dateTime);
175 void SetFromUTCDateTime(const time_t &dateTime);
176 void SetFromRFC1123DateTime(const CStdString &dateTime);
178 /*! \brief set from a database datetime format YYYY-MM-DD HH:MM:SS
179 \sa GetAsDBDateTime()
181 void SetFromDBDateTime(const CStdString &dateTime);
183 void GetAsSystemTime(SYSTEMTIME& time) const;
184 void GetAsTime(time_t& time) const;
185 void GetAsTm(tm& time) const;
186 void GetAsTimeStamp(FILETIME& time) const;
188 CDateTime GetAsUTCDateTime() const;
189 CStdString GetAsSaveString() const;
190 CStdString GetAsDBDateTime() const;
191 CStdString GetAsDBDate() const;
192 CStdString GetAsLocalizedDate(bool longDate=false, bool withShortNames=true) const;
193 CStdString GetAsLocalizedDate(const CStdString &strFormat, bool withShortNames=true) const;
194 CStdString GetAsLocalizedTime(const CStdString &format, bool withSeconds=true) const;
195 CStdString GetAsLocalizedDateTime(bool longDate=false, bool withSeconds=true) const;
196 CStdString GetAsRFC1123DateTime() const;
198 void SetValid(bool yesNo);
199 bool IsValid() const;
201 static void ResetTimezoneBias(void);
202 static CDateTimeSpan GetTimezoneBias(void);
205 bool ToFileTime(const SYSTEMTIME& time, FILETIME& fileTime) const;
206 bool ToFileTime(const time_t& time, FILETIME& fileTime) const;
207 bool ToFileTime(const tm& time, FILETIME& fileTime) const;
209 void ToULargeInt(ULARGE_INTEGER& time) const;
210 void FromULargeInt(const ULARGE_INTEGER& time);