4 * Copyright (C) 2005-2008 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, write to
19 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20 * http://www.gnu.org/copyleft/gpl.html
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};
48 CDateTimeSpan(const CDateTimeSpan& span);
49 CDateTimeSpan(int day, int hour, int minute, int second);
51 bool operator >(const CDateTimeSpan& right) const;
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;
58 CDateTimeSpan operator +(const CDateTimeSpan& right) const;
59 CDateTimeSpan operator -(const CDateTimeSpan& right) const;
61 const CDateTimeSpan& operator +=(const CDateTimeSpan& right);
62 const CDateTimeSpan& operator -=(const CDateTimeSpan& right);
64 void SetDateTimeSpan(int day, int hour, int minute, int second);
65 void SetFromPeriod(const CStdString &period);
66 void SetFromTimeString(const CStdString& time);
70 int GetMinutes() const;
71 int GetSeconds() const;
74 void ToULargeInt(ULARGE_INTEGER& time) const;
75 void FromULargeInt(const ULARGE_INTEGER& time);
80 friend class CDateTime;
83 /// \brief DateTime class, which uses FILETIME as it's base.
84 class CDateTime : public IArchivable
88 CDateTime(const CDateTime& time);
89 CDateTime(const SYSTEMTIME& time);
90 CDateTime(const FILETIME& time);
91 CDateTime(const time_t& time);
92 CDateTime(const tm& time);
93 CDateTime(int year, int month, int day, int hour, int minute, int second);
94 virtual ~CDateTime() {}
96 void SetFromDateString(const CStdString &date);
98 static CDateTime GetCurrentDateTime();
99 static CDateTime GetUTCDateTime();
101 const CDateTime& operator =(const SYSTEMTIME& right);
102 const CDateTime& operator =(const FILETIME& right);
103 const CDateTime& operator =(const time_t& right);
104 const CDateTime& operator =(const tm& right);
106 bool operator >(const CDateTime& right) const;
107 bool operator >=(const CDateTime& right) const;
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;
113 bool operator >(const FILETIME& right) const;
114 bool operator >=(const FILETIME& 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;
120 bool operator >(const SYSTEMTIME& right) const;
121 bool operator >=(const SYSTEMTIME& 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;
127 bool operator >(const time_t& right) const;
128 bool operator >=(const time_t& 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;
134 bool operator >(const tm& right) const;
135 bool operator >=(const tm& 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;
141 CDateTime operator +(const CDateTimeSpan& right) const;
142 CDateTime operator -(const CDateTimeSpan& right) const;
144 const CDateTime& operator +=(const CDateTimeSpan& right);
145 const CDateTime& operator -=(const CDateTimeSpan& right);
147 CDateTimeSpan operator -(const CDateTime& right) const;
149 operator FILETIME() const;
151 virtual void Archive(CArchive& ar);
156 int GetMonth() const;
159 int GetMinute() const;
160 int GetSecond() const;
161 int GetDayOfWeek() const;
162 int GetMinuteOfDay() const;
164 void SetDateTime(int year, int month, int day, int hour, int minute, int second);
165 void SetDate(int year, int month, int day);
166 void SetTime(int hour, int minute, int second);
167 void SetFromDBDate(const CStdString &date);
168 void SetFromDBTime(const CStdString &time);
169 void SetFromW3CDate(const CStdString &date);
171 /*! \brief set from a database datetime format YYYY-MM-DD HH:MM:SS
172 \sa GetAsDBDateTime()
174 void SetFromDBDateTime(const CStdString &dateTime);
176 void GetAsSystemTime(SYSTEMTIME& time) const;
177 void GetAsTime(time_t& time) const;
178 void GetAsTm(tm& time) const;
179 void GetAsTimeStamp(FILETIME& time) const;
181 CDateTime GetAsUTCDateTime() const;
182 CStdString GetAsDBDateTime() const;
183 CStdString GetAsDBDate() const;
184 CStdString GetAsLocalizedDate(bool longDate=false, bool withShortNames=true) const;
185 CStdString GetAsLocalizedTime(const CStdString &format, bool withSeconds=true) const;
186 CStdString GetAsLocalizedDateTime(bool longDate=false, bool withSeconds=true) const;
187 CStdString GetAsRFC1123DateTime() const;
189 void SetValid(bool yesNo);
190 bool IsValid() const;
193 bool ToFileTime(const SYSTEMTIME& time, FILETIME& fileTime) const;
194 bool ToFileTime(const time_t& time, FILETIME& fileTime) const;
195 bool ToFileTime(const tm& time, FILETIME& fileTime) const;
197 void ToULargeInt(ULARGE_INTEGER& time) const;
198 void FromULargeInt(const ULARGE_INTEGER& time);